Hide Table of Contents

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



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:   Use PhotoWorks Caustic Options Example (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) 2010 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.