Hi,
I need to render hundreds of full colour JPG for website as well as contour only images for printed instructions.
so I used this macro which is pretty much a slightly modified version of the official api online example.
I intented to call this fuction a coule of times, and use Contour Options to alter the render result.
the debug line prints parameter as expected, but the parameter has no influence on the render result.
Is this a bug or my mistake?
apreciate your help
Sub swRenderImage(ImageHeight, ImageWidth As Integer, ImageFormat As Integer, ContourOption As Boolean, Suffix As String)
Dim swRayTraceRenderer As SldWorks.RayTraceRenderer
Dim swRayTraceRenderOptions As SldWorks.RayTraceRendererOptions
Dim Errors As Long
Dim Warnings As Long
Dim sfile As String 'dim source file
Dim tfile As String 'dim target file
Dim status As Boolean'Set swApp = Application.SldWorks
'Set swModel = swApp.ActiveDoc
'OpenDoc6(sfile, 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.UseSolidWorksViewAspectRatio = False
swRayTraceRenderOptions.UseSceneBackgroundImageAspectRatio = FalseswRayTraceRenderOptions.ImageHeight = ImageHeight
Debug.Print " ImageHeight = " & swRayTraceRenderOptions.ImageHeight
swRayTraceRenderOptions.ImageWidth = ImageWidth
Debug.Print " ImageWidth = " & swRayTraceRenderOptions.ImageWidth
swRayTraceRenderOptions.ImageFormat = ImageFormat
Debug.Print " ImageFormat = " & swRayTraceRenderOptions.ImageFormat
swRayTraceRenderOptions.PreviewRenderQuality = swRenderQuality_Good
Debug.Print " PreviewRenderQuality = " & swRayTraceRenderOptions.PreviewRenderQuality
swRayTraceRenderOptions.FinalRenderQuality = swRenderQuality_Best
Debug.Print " FinalRenderQuality = " & swRayTraceRenderOptions.FinalRenderQuality'BloomOption
swRayTraceRenderOptions.BloomEnabled = False
Debug.Print " BloomEnabled = " & swRayTraceRenderOptions.BloomEnabled
swRayTraceRenderOptions.BloomThreshold = 70
Debug.Print " BloomThreshold = " & swRayTraceRenderOptions.BloomThreshold
swRayTraceRenderOptions.BloomRadius = 4
Debug.Print " BloomRadius = " & swRayTraceRenderOptions.BloomRadius'ContourOption ( I think setting contour Options reset Shaded Contour option )
swRayTraceRenderOptions.ContourEnabled = ContourOption
Debug.Print " ContourEnabled = " & swRayTraceRenderOptions.ContourEnabled
' it seems this is not working in 2012
swRayTraceRenderOptions.ShadedContour = False
Debug.Print " ShadedContour = " & swRayTraceRenderOptions.ShadedContour
swRayTraceRenderOptions.ContourLineThickness = 5
Debug.Print " ContourLineThickness = " & swRayTraceRenderOptions.ContourLineThickness
swRayTraceRenderOptions.ContourLineColor = RGB(0, 0, 0)
Debug.Print " ContourLineColor = " & swRayTraceRenderOptions.ContourLineColor' Display the preview window
'status = swRayTraceRenderer.DisplayPreviewWindow' Close render
'status = swRayTraceRenderer.CloseRayTraceRenderIf ContourOption = True Then
' Invoke final render window
status = swRayTraceRenderer.InvokeFinalRender
End If' Abort final render window
'status = swRayTraceRenderer.AbortFinalRender' Render to format
Dim FSO As FileSystemObject
Set FSO = CreateObject("Scripting.FileSystemObject")
Debug.Print FSO.GetBaseName(sfile)
Debug.Print FSO.GetFileName(sfile)
Debug.Print FSO.GetParentFolderName(sfile)'Assign a Target File Name
sfile = swModel.GetPathNametfile = FSO.GetParentFolderName(sfile) & "\" & FSO.GetBaseName(sfile) & Suffix
Debug.Print "Target = " & tfile
status = swRayTraceRenderer.RenderToFile(tfile, 0, 0)
Set swRayTraceRenderOptions = Nothing
' Close render
status = swRayTraceRenderer.CloseRayTraceRender
End Sub
SolidworksApi macros