Hide Table of Contents

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



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 Contour 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.