Hide Table of Contents

Render Model (VBA)

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. The c:\temp folder exists.
' 3. PhotoView 360 is loaded in SolidWorks.
' 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.
'--------------------------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swRayTraceRenderer As SldWorks.RayTraceRenderer
Dim swRayTraceRenderOptions As SldWorks.RayTraceRendererOptions
Dim errors As Long
Dim warnings As Long
Dim fileName As String
Dim status As Boolean
Sub main()
Set swApp = Application.SldWorks
fileName = "c:\Program Files\SolidWorks Corp\SolidWorks\samples\tutorial\routing-pipes\fittings\filter.sldprt"
Set swModel = swApp.OpenDoc6(fileName, swDocPART, swOpenDocOptions_Silent, "", errors, warnings)
' Access PhotoView 360
Set swRayTraceRenderer = swApp.GetRayTraceRenderer(swPhotoView)
' Get and set rendering options
Set swRayTraceRenderOptions = 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 = swImageFormat_HDR
Debug.Print "  ImageFormat          = " & swRayTraceRenderOptions.ImageFormat
swRayTraceRenderOptions.PreviewRenderQuality = swRenderQuality_Better
Debug.Print "  PreviewRenderQuality = " & swRayTraceRenderOptions.PreviewRenderQuality
swRayTraceRenderOptions.FinalRenderQuality = 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 = swRenderQuality_Good
' Render to HDR format (format extension omitted)
status = swRayTraceRenderer.rendertofile("c:\temp\Filter_2", 0, 0)
Set swRayTraceRenderOptions = Nothing
' Close render
status = swRayTraceRenderer.CloseRayTraceRender
End Sub
'------------------------------------


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 (VBA)
*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.