Hide Table of Contents

Add a PhotoWorks Scene Example (VBA)

This example shows how to:

  • manipulate SolidWorks lights and the effect in PhotoWorks.

  • add a scene to the image.

  • render the image to the screen.

 

'------------------------------------------

 

' Preconditions: The PhotoWorks add-in is loaded, and the specified

'                SolidWorks part file exists.

'

' Postconditions:

'  (1) Cone angle is changed.

'  (2) Scene is added to the image.

'  (3) Image is rendered to the screen.

'

'---------------------------------------------

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 strInternalLightName    As String

    Dim strLightName            As String

    Dim dAmbient                As Double

    Dim dDiffuse                As Double

    Dim dSpecular               As Double

    Dim lColor                  As Long

    Dim bEnabled                As Boolean

    Dim bFixed                  As Boolean

    Dim dLocationX              As Double

    Dim dLocationY              As Double

    Dim dLocationZ              As Double

    Dim dTargetX                As Double

    Dim dTargetY                As Double

    Dim dTargetZ                As Double

    Dim dConeAngle              As Double

    Dim lNumLights              As Long

    Dim lLightItr               As Long

    Dim vLightProperties        As Variant

    

    ' 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 a SolidWorks part file

    ' NOTE: Instead of Flashlight-complete.sldprt, substitute the

    ' name of your SolidWorks parts file. The part

    ' should have a light named Spot1.

    Set swModel = swApp.OpenDoc6("Flashlight-complete.sldprt", swDocPART, swOpenDocOptions_Silent, "", lErrors, lWarnings)

        

    ' Render the image to your screen

    bRetVal = pwAddIn.RenderToScreen

    

    '

    ' Get the spotlight properties

    '

    

    ' This is the light to modify

    strLightName = "Spot1"

        

    ' Get number of lights in the model

    lNumLights = swModel.GetLightSourceCount

    ' Traverse all lights

    For lLightItr = 0 To (lNumLights - 1)

        Debug.Print "  SolidWorks Name = " & swModel.GetLightSourceName(lLightItr)

        Debug.Print "  User       Name = " & swModel.LightSourceUserName(lLightItr)

        

        If swModel.LightSourceUserName(lLightItr) = strLightName Then

        

            ' Get the internal name of the light

            strInternalLightName = swModel.GetLightSourceName(lLightItr)

            

            ' Get the light properties

            vLightProperties = swModel.LightSourcePropertyValues(lLightItr)

            

            ' Change the cone angle

            vLightProperties(11) = vLightProperties(11) * 0.5

            

            ' Update light properties

            swModel.LightSourcePropertyValues(lLightItr) = vLightProperties

        End If

    Next lLightItr

    ' Effectuate changes

    swModel.EditRebuild3

    

    ' Get the light properties in another way

    bRetVal = swModel.GetSpotlightProperties(strInternalLightName, dAmbient, dDiffuse, dSpecular, lColor, bEnabled, bFixed, _

                                             dLocationX, dLocationY, dLocationZ, dTargetX, dTargetY, dTargetZ, dConeAngle)

                  

    Debug.Print strLightName & ":"

    Debug.Print "  ConeAngle = " & CStr(dConeAngle)

  

    '

    ' Render the image to screen to see the change

    '

    

    ' Clear the screen before re-rendering the image

    pwOpt.ClearImageBeforeRendering = True

    

    ' Render the image to screen again

    bRetVal = pwAddIn.RenderToScreen    

    

    ' Load a different scene

    ' NOTE: The path specified is the default SolidWorks and PhotoWorks

    ' installation path; substitute your path if

    ' it is not the same as the default

    bRetVal = pwAddIn.SetScene("bRetVal = pwAddIn.SetScene("C:\Program Files\SolidWorks\photoworks\data\Scenes\Showrooms\Mirror.p2s")

    ")    

    

    ' Render the image to screen again

    bRetVal = pwAddIn.RenderToScreen        

        

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:   Add a PhotoWorks Scene 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.