Hide Table of Contents

Load and Unload the PhotoWorks Add-in Example (VBA)

This example shows how to load and unload the PhotoWorks add-in using its DLL.

 

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

'

' Preconditions:

'     (1) PhotoWorks add-in not loaded.

'     (2) Specified SolidWorks part file exists.

'

' Postconditions:

'     (1) PhotoWorks add-in is loaded.

'     (2) All model views, except for Normal to, are

'         displayed, and the model is rendered to the

'         screen in each view.

'     (3) PhotoWorks add-in is unloaded.

'

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

Option Explicit

Dim swApp As SldWorks.SldWorks

Sub main()

    

    Dim swModel                 As SldWorks.ModelDoc2

    Dim pwAddIn                 As PhotoWorks.PhotoWorks

    Dim pwOpt                   As PhotoWorks.PwOptions

    Dim bRetVal                 As Boolean

    Dim vModelViewNames         As Variant

    Dim lViewItr                As Long

    Dim lErrors                 As Long

    Dim lWarnings               As Long

    Dim strDllFileName          As String

    Dim strExecutablePath       As String

    Dim lStatus                 As Long

    

    ' Get the SolidWorks application

    Set swApp = Application.SldWorks

    '

    ' Load the add-in

    '

    ' Compose the name of the DLL to load by   

    ' getting the path where the SolidWorks executable exists

    ' relative to where the PhotoWorks DLL exists

    strExecutablePath = swApp.GetExecutablePath

    strDllFileName = strExecutablePath & "\photoworks\pworks.dll"

     

    ' Get the PhotoWorks add-in

    Set pwAddIn = swApp.GetAddInObject("PhotoWorks.PhotoWorks")

    

    

    ' Check to see if the add-in is already loaded

    If pwAddIn Is Nothing Then

        ' Load the DLL

        lStatus = swApp.LoadAddIn(strDllFileName)

    

        If lStatus <> 0 Then

    

            ' DLL was not loaded

 

            Select Case lStatus

           

                Case -1:

                    Debug.Print strDllFileName & " Not loaded: unknown error."

                Case 1:

                    Debug.Print strDllFileName & " Not loaded: not an error."

                Case 2:

                    Debug.Print strDllFileName & " Not loaded: already loaded."

                

            End Select

            

            Exit Sub

        

        Else

        

            ' DLL was loaded

            

            ' Get the PhotoWorks add-in

            Set pwAddIn = swApp.GetAddInObject("PhotoWorks.PhotoWorks")

        

            If pwAddIn Is Nothing Then

        

                Debug.Print "No PhotoWorks add-in"

                              

                Exit Sub

            

            End If

             

        End If

    Else

        ' PhotoWorks add-in was already loaded; step over this assert

        Debug.Assert (False)

    End If

    '

    ' PhotoWorks add-in loaded

    '

    '

    ' Use the add-in in SolidWorks 2006 and later

    '

 

    ' Get the PhotoWorks options

    Set pwOpt = pwAddIn.PwOptions()

         

         

    ' Open a Solidworks part file

    ' NOTE: Instead of Idler Arm - complete.sldprt, specify

    ' the name of the SolidWorks part file that you want to open

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

           

    ' Get all of the named views

    vModelViewNames = swModel.GetModelViewNames

         

    If Not IsEmpty(vModelViewNames) Then

         

        Debug.Print "Views:"

        For lViewItr = LBound(vModelViewNames) To UBound(vModelViewNames)

             

            ' To avoid having to select a plane, skip the Normal to view

            If vModelViewNames(lViewItr) = "*Normal To" Then

                 

                Debug.Print "  " & vModelViewNames(lViewItr) & "(skipped)"

                     

            Else

                 

                Debug.Print "  " & vModelViewNames(lViewItr)             

                     

                ' Activate view of this name

                swModel.ShowNamedView2 vModelViewNames(lViewItr), -1

                 

                ' Zoom to fit

                swModel.ViewZoomtofit2

                     

                ' Render to screen

                bRetVal = pwAddIn.RenderToScreen

                     

            End If

             

        Next lViewItr

         

    End If

   

    '

    ' Unload the add-in

    '

    

    ' Unload the DLL by releasing the PhotoWorks options and add-in objects

    Set pwOpt = Nothing

    Set pwAddIn = Nothing

   

   

    ' Unload the DLL

    lStatus = swApp.UnloadAddIn(strDllFileName)

    

    If lStatus = 0 Then

        Debug.Print strDllFileName & " unloaded."

    Else

        Debug.Print strDllFileName & " not unloaded."

    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:   Load and Unload the PhotoWorks Add-in 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.