Use PhotoWorks Contour Options Example (VBA)
This example shows how to use the different PhotoWorks contour options.
'---------------------------------------------
'
' Preconditions: The PhotoWorks add-in is loaded, and
the specified
' SolidWorks
part file exists.
'
' Postconditions: The part is rendered to three separate
files as:
' *
Model only
' *
Contours only
' *
Model and contours
'
'---------------------------------------------
Option Explicit
Sub main()
Dim
swApp As SldWorks.SldWorks
Dim
pwAddIn As
PhotoWorks.PhotoWorks
Dim
pwOpt As
PhotoWorks.PwOptions
Dim
strTargetDirectory As
String
Dim
strTargetFileName As
String
Dim
strTargetFileExtension As
String
Dim
strTargetPostFix As
String
Dim
bRetVal As
Boolean
Dim
swModel As
SldWorks.ModelDoc2
Dim
lErrors As
Long
Dim
lWarnings As
Long
Dim
bOverWrite As
Boolean
'
Get the SolidWorks application
Set
swApp = Application.SldWorks
'
Get the PhotoWorks add-in
Set
pwAddIn = swApp.GetAddInObject("PhotoWorks.PhotoWorks")
'
Get the PhotoWorks options
Set
pwOpt = pwAddIn.PwOptions()
'
Open the SolidWorks part file
'
NOTE: Instead of micrometer.sldprt,
specify the name
'
of the SolidWorks part file that you want to open
Set
swModel = swApp.OpenDoc6("micrometer.sldprt", swDocPART, swOpenDocOptions_Silent,
"", lErrors, lWarnings)
'
Set the filename extension
'
NOTE: Setting the filename extension
does not automatically
'
add the corresponding filename extension to the filename.
pwAddIn.RenderFileFormat = PhotoWorks.PW_RenderFileFormat.pwFileFormatJPG
'
Set the dimensions in pixels
pwAddIn.RenderFileUnits = PhotoWorks.PW_RenderFileUnits.pwPixels
pwAddIn.RenderFileWidth = 320
pwAddIn.RenderFileHeight = 240
'
Set the elements of file name
strTargetDirectory
= "C:\temp\"
strTargetFileName
= "micrometer"
strTargetFileExtension
= ".jpg"
'
Overwrite target file
bOverWrite
= True
'
'
Render the model without contours
'
strTargetPostFix
= "ModelOnly"
pwOpt.ContourRenderingMode = PW_ContourMode.pwModelOnly
pwOpt.ContourLineThickness = 2
pwOpt.ContourLineColor = RGB(0, 0, 255) '
Blue
'
Compose the file name
pwAddIn.RenderFileName = strTargetDirectory
& strTargetFileName & strTargetPostFix & strTargetFileExtension
'
Render the image
bRetVal
= pwAddIn.RenderToFile(bOverWrite)
'
Check the return value
If
bRetVal = False Then
Debug.Print
"Render to file: Failed."
Else
Debug.Print
"Render to file: Success. Result in " & pwAddIn.RenderFileName
& "."
End
If
'
'
Render the model with contours
'
strTargetPostFix
= "ModelAndContours"
'
Change the contour settings
pwOpt.ContourRenderingMode = pwModelAndContours
pwOpt.ContourLineThickness = 1
pwOpt.ContourLineColor = RGB(255, 255, 255)
' White
'
Compose the file name
pwAddIn.RenderFileName = strTargetDirectory
& strTargetFileName & strTargetPostFix & strTargetFileExtension
'
Render the image
bRetVal
= pwAddIn.RenderToFile(bOverWrite)
'
Check the return value
If
bRetVal = False Then
Debug.Print
"Render to file: Failed."
Else
Debug.Print
"Render to file: Success. Result in " & pwAddIn.RenderFileName
& "."
End
If
'
'
Render the contours only
'
strTargetPostFix
= "ContoursOnly"
pwOpt.ContourRenderingMode = pwContoursOnly
pwOpt.ContourLineThickness = 1
pwOpt.ContourLineColor = RGB(255, 255, 255)
' White
pwOpt.ContourBackgroundColor = RGB(0, 128,
192) ' Blue
'
Compose the file name
pwAddIn.RenderFileName = strTargetDirectory
& strTargetFileName & strTargetPostFix & strTargetFileExtension
'
Render the image
bRetVal
= pwAddIn.RenderToFile(bOverWrite)
'
Check the return value
If
bRetVal = False Then
Debug.Print
"Render to file: Failed."
Else
Debug.Print
"Render to file: Success. Result in " & pwAddIn.RenderFileName
& "."
End
If
End Sub