Hide Table of Contents
IRenderNotificationHandler Interface

Allows access to the render notification handler.

.NET Syntax

Visual Basic (Declaration) 
Public Interface IRenderNotificationHandler 
Visual Basic (Usage) 
Dim instance As IRenderNotificationHandler
C# 
public interface IRenderNotificationHandler 
C++/CLI 
public interface class IRenderNotificationHandler 

Example

The following C# class demonstrates how to implement this handler for two render events, RenderActionChanged and PreviewRequested. Note that this code is part of a larger add-in which is posted in the SOLIDWORKS API Support Knowledge Base (SOLIDWORKS Visualize API Sample Plugin (C#)):

=======================================

using System.IO;
using System.Timers;
using System.Windows.Media.Imaging;
using SolidWorks.Visualize.Interfaces;

namespace SWVizAPISample
{

public class RenderHandler : IRenderNotificationHandler
    {
        private readonly Timer _requestPreviewTimer;

        private bool _previewRequestPending = false;
       
        public event ChangeRenderActionHandler RenderActionChanged;

        public event PreviewRequestHandler PreviewRequested;

        public RenderHandler()
        {
            _requestPreviewTimer = new Timer(5000); // every 5s
            _requestPreviewTimer.Elapsed += RequestPreview;
            RenderProgressDialog = new OutputViewerDialog("Output Viewer Dialog");
            RenderProgressDialog.ViewModel.RenderCanceled += CancelRender;
            RenderProgressDialog.ViewModel.RenderCanceledAndSave += CancelAndSaveRender;
        }

        public OutputViewerDialog RenderProgressDialog { get; }

        public Stream BitmapSourceToStream(BitmapSource bitmapSource)
        {
            MemoryStream stream = new MemoryStream();
            BitmapEncoder encoder = new PngBitmapEncoder(); // Or any other suitable encoder like JpegBitmapEncoder
            encoder.Frames.Add(BitmapFrame.Create(bitmapSource));
            encoder.Save(stream);
            stream.Seek(0, SeekOrigin.Begin);
            return stream;
        }

        public void CancelRender()
            => RenderActionChanged?.Invoke(RenderAction_e.Cancel);

        public void CancelAndSaveRender()
            => RenderActionChanged?.Invoke(RenderAction_e.CancelAndSave);

        private void RequestPreview(object sender, ElapsedEventArgs e)
        {
            if (_previewRequestPending)
            {
                return;
            }

            float previewY = 300.0f;
            float previewX = 400.0f;

            if (RenderProgressDialog.ViewModel.AspectRatio >= previewX / previewY)
            {
                previewY = previewX / RenderProgressDialog.ViewModel.AspectRatio;
            }
            else
            {
                previewX = previewY / RenderProgressDialog.ViewModel.AspectRatio;
            }

            PreviewRequested?.Invoke((int)previewX, (int)previewY);
            _previewRequestPending = true;
        }
           

        public void RendererPropertyChangedNotify(RenderProperty_e renderProperty,
            IRendererPropertiesStatus rendererPropertiesStatus)
        {
            if (!_requestPreviewTimer.Enabled)
            {
                _requestPreviewTimer.Start();
            }

            if (renderProperty == RenderProperty_e.CurrentProgress)
            {
                RenderProgressDialog.ViewModel.RenderProgress = (double)(rendererPropertiesStatus.CurrentProgress * 100);
            }
            else if (renderProperty == RenderProperty_e.FramesRendered)
            {
                RenderProgressDialog.ViewModel.FramesRendered = rendererPropertiesStatus.FramesRendered;
            }
            else if (renderProperty == RenderProperty_e.ElapsedTime)
            {
                RenderProgressDialog.ViewModel.TimeSpan = rendererPropertiesStatus.ElapsedTime;
            }
            else if (renderProperty == RenderProperty_e.RenderJobStatus)
            {
                if (rendererPropertiesStatus.RenderJobStatus == RenderJobStatus.JobComplete ||
                    rendererPropertiesStatus.RenderJobStatus == RenderJobStatus.JobCancelled ||
                    rendererPropertiesStatus.RenderJobStatus == RenderJobStatus.JobAborted ||
                    rendererPropertiesStatus.RenderJobStatus == RenderJobStatus.JobFailed)
                {
                    _requestPreviewTimer.Stop();
                    RenderProgressDialog.ViewModel.RenderCanceled -= CancelRender;
                    RenderProgressDialog.ViewModel.RenderCanceledAndSave -= CancelAndSaveRender;
                }
            }
            else if (renderProperty == RenderProperty_e.RendererPreviewComplete)
            {
                if (rendererPropertiesStatus.BitmapPreviewImageSource != null)
                {
                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.BeginInit();
                    bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
                    bitmapImage.StreamSource = BitmapSourceToStream(rendererPropertiesStatus.BitmapPreviewImageSource);
                    bitmapImage.EndInit();
                    RenderProgressDialog.ViewModel.RenderedImage = bitmapImage;

                    _previewRequestPending = false;
                }
            }
        }
    }

}

See Also



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   IRenderNotificationHandler Interface
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:

x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2025 SP2

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.