Hide Table of Contents

Render Model (C#)

This example shows how to access PhotoView 360 to render a model and save the rendered image to a Windows BMP file and a HDR file.

//--------------------------------------------------------------
// Preconditions:
// 1. Specified part exists.
// 2. c:\temp folder exists.
// 3. PhotoView 360 is loaded.
// 4. Open the Immediate window.
// 5. Run macro.
//
// Postconditions:
// 1. Specified options are changed.
// 2. A Windows Bitmap file and a HDR
//    file are created containing rendered images of
//    the open part.
//--------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
using System.Diagnostics;

namespace RayTraceRendererCSharp.csproj
{

    
partial class SolidWorksMacro
    {

        
public void Main()
        {

            ModelDoc2 swModel;
            RayTraceRenderer swRayTraceRenderer;
            RayTraceRendererOptions swRayTraceRenderOptions;
            
int errors = 0;
            
int warnings = 0;
            
string fileName = null;
            
bool status = false;

            fileName =
"c:\\Program Files\\SolidWorks Corp\\SolidWorks\\samples\\tutorial\\routing-pipes\\fittings\\filter.sldprt";
            swModel = (ModelDoc2)swApp.OpenDoc6(fileName, (
int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);

            
// Access PhotoView 360
            swRayTraceRenderer = (RayTraceRenderer)swApp.GetRayTraceRenderer((int)swRayTraceRenderType_e.swPhotoView);

            
// Get and set rendering options
            swRayTraceRenderOptions = (RayTraceRendererOptions)swRayTraceRenderer.RayTraceRendererOptions;

            
//Get current rendering values
            Debug.Print("Current rendering values");
            
Debug.Print(" ImageHeight = " + swRayTraceRenderOptions.ImageHeight);
            
Debug.Print(" ImageWidth = " + swRayTraceRenderOptions.ImageWidth);
            
Debug.Print(" ImageFormat = " + swRayTraceRenderOptions.ImageFormat);
            
Debug.Print(" PreviewRenderQuality = " + swRayTraceRenderOptions.PreviewRenderQuality);
            
Debug.Print(" FinalRenderQuality = " + swRayTraceRenderOptions.FinalRenderQuality);
            
Debug.Print(" BloomEnabled = " + swRayTraceRenderOptions.BloomEnabled);
            
Debug.Print(" BloomThreshold = " + swRayTraceRenderOptions.BloomThreshold);
            
Debug.Print(" BloomRadius = " + swRayTraceRenderOptions.BloomRadius);
            
Debug.Print(" ContourEnabled = " + swRayTraceRenderOptions.ContourEnabled);
            
Debug.Print(" ShadedContour = " + swRayTraceRenderOptions.ShadedContour);
            
Debug.Print(" ContourLineThickness = " + swRayTraceRenderOptions.ContourLineThickness);
            
Debug.Print(" ContourLineColor = " + swRayTraceRenderOptions.ContourLineColor);

            
Debug.Print(" ");

            
// Change rendering values
            Debug.Print("New rendering values");
            swRayTraceRenderOptions.ImageHeight = 567;
            
Debug.Print(" ImageHeight = " + swRayTraceRenderOptions.ImageHeight);
            swRayTraceRenderOptions.ImageWidth = 678;
            
Debug.Print(" ImageWidth = " + swRayTraceRenderOptions.ImageWidth);
            swRayTraceRenderOptions.ImageFormat = (
int)swRayTraceRenderImageFormat_e.swImageFormat_HDR;
            
Debug.Print(" ImageFormat = " + swRayTraceRenderOptions.ImageFormat);
            swRayTraceRenderOptions.PreviewRenderQuality = (
int)swRayTraceRenderQuality_e.swRenderQuality_Better;
            
Debug.Print(" PreviewRenderQuality = " + swRayTraceRenderOptions.PreviewRenderQuality);
            swRayTraceRenderOptions.FinalRenderQuality = (
int)swRayTraceRenderQuality_e.swRenderQuality_Best;
            
Debug.Print(" FinalRenderQuality = " + swRayTraceRenderOptions.FinalRenderQuality);
            swRayTraceRenderOptions.BloomEnabled =
false;
            
Debug.Print(" BloomEnabled = " + swRayTraceRenderOptions.BloomEnabled);
            swRayTraceRenderOptions.BloomThreshold = 70;
            
Debug.Print(" BloomThreshold = " + swRayTraceRenderOptions.BloomThreshold);
            swRayTraceRenderOptions.BloomRadius = 4;
            
Debug.Print(" BloomRadius = " + swRayTraceRenderOptions.BloomRadius);
            swRayTraceRenderOptions.ContourEnabled =
true;
            
Debug.Print(" ContourEnabled = " + swRayTraceRenderOptions.ContourEnabled);
            swRayTraceRenderOptions.ShadedContour =
false;
            
Debug.Print(" ShadedContour = " + swRayTraceRenderOptions.ShadedContour);
            swRayTraceRenderOptions.ContourLineThickness = 3;
            
Debug.Print(" ContourLineThickness = " + swRayTraceRenderOptions.ContourLineThickness);
            swRayTraceRenderOptions.ContourLineColor = 255;
            
Debug.Print(" ContourLineColor = " + swRayTraceRenderOptions.ContourLineColor);

            
// Display the preview window
            status = swRayTraceRenderer.DisplayPreviewWindow();

            
// Close render
            status = swRayTraceRenderer.CloseRayTraceRender();
            
// Invoke final render window
            status = swRayTraceRenderer.InvokeFinalRender();

            
// Abort final render window
            status = swRayTraceRenderer.AbortFinalRender();

            
// Render to Windows Bitmap format
            status = swRayTraceRenderer.RenderToFile("c:\\temp\\Filter_1.bmp", 0, 0);

            swRayTraceRenderOptions.FinalRenderQuality = (
int)swRayTraceRenderQuality_e.swRenderQuality_Good;

            
// Render to HDR format (format extension omitted)
            status = swRayTraceRenderer.RenderToFile("c:\\temp\\Filter_2", 0, 0);

            swRayTraceRenderOptions =
null;

            
// Close render

            status = swRayTraceRenderer.CloseRayTraceRender();
        }
        
//------------------------------------

        /// <summary>
        /// The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public
SldWorks swApp;


    }
}




 



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:   Render Model (C#)
*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) 2013 SP05

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.