Use PhotoWorks Caustic Options Example (VBA)
This example shows how to use different PhotoWorks caustic options.
'---------------------------------------------
'
' Preconditions: PhotoWorks add-in is loaded, and the
specified
' SolidWorks
part file exists.
'
' Postconditions: Three .jpg files are created in your
' c:\temp
folder.
'
'
'---------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Sub main()
Dim
pwAddIn As
PhotoWorks.PhotoWorks
Dim
pwOpt As
PhotoWorks.PwOptions
Dim
bRetVal As
Boolean
Dim
swModel As
SldWorks.ModelDoc2
Dim
swModelView As
SldWorks.ModelView
Dim
lErrors As
Long
Dim
lWarnings As
Long
Dim
strTargetDirectory As
String
Dim
strTargetFileName As
String
Dim
strBaseName As
String
Dim
strTargetFileExtension As
String
Dim
bOverWrite As
Boolean
Dim
dStartRadius As
Double
Dim
ddStartRadius As
Double
Dim
dRadiusIncrement As
Double
Dim
lRadiusIdx As
Long
Dim
dRadius As
Double
Dim
lNumSteps As
Long
'
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 specified part file
'
NOTE: Instead of InsideBox.Sldprt,
specify the name
'
of the SolidWorks part file that you want to open
Set
swModel = swApp.OpenDoc6("InsideBox.sldprt", swDocPART, swOpenDocOptions_Silent,
"", lErrors, lWarnings)
'
This part has one camera
'
Activate the camera so that you can see inside the box
Set
swModelView = swModel.ActiveView
bRetVal
= swModelView.SetCameraByName("Camera1")
'
Set dimensions in pixels
pwAddIn.RenderFileUnits = PhotoWorks.PW_RenderFileUnits.pwPixels
pwAddIn.RenderFileWidth = 320
pwAddIn.RenderFileHeight = 320
'
Set the elements of the file name
strTargetDirectory
= "C:\temp\"
strBaseName
= "CausticRadiusExample"
strTargetFileExtension
= ".jpg"
'
Overwrite target file
bOverWrite
= True
'
'
Set caustic options
'
'
Enable caustics
pwOpt.EnableCaustic = True
'
Enable the default caustic radius
pwOpt.UseCausticDefaultRadius = True
'
Get the default caustic radius
dStartRadius
= pwOpt.CausticRadiusDefault
'
Disable the default radius so that
'
you can change the custom caustic radius
pwOpt.UseCausticDefaultRadius = False
'
Compute a meaningful increment
dRadiusIncrement
= dStartRadius * 0.05
'
Initialize the radius variable
dRadius
= dStartRadius
'
Set the number of steps in the loop
lNumSteps
= 3
'
Render the image at each radius increment
For
lRadiusIdx = 1 To lNumSteps
'
Start by setting the custom caustic radius
'
to the default caustic radius and then
'
increment the custom caustic radius at each pass
pwOpt.CausticRadius = dRadius
'
Check the radius
If
dRadius >= pwOpt.CausticsRadiusMinimum
And dRadius <= pwOpt.CausticsAccuracyMaximum
Then
'
Compose the output file name
strTargetFileName
= strTargetDirectory & strBaseName & "_" & CStr(lRadiusIdx)
& strTargetFileExtension
'
Set the output file name
pwAddIn.RenderFileName = strTargetFileName
'
Render the image to the file
pwAddIn.RenderToFile (bOverWrite)
'
Increment the radius
dRadius
= dRadius + dRadiusIncrement
End
If
Next
lRadiusIdx
'
Reset the custom caustic radius back to the default caustic radius
pwOpt.CausticRadius = dStartRadius
End Sub