Hide Table of Contents

Run SolidWorks Design Checker Example (VBA)

This example shows how to check the active document using the SolidWorks Design Checker API.

 

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

'

' Preconditions:

'           (1) SolidWorks Design Checker add-in is not

'               loaded.

'           (2) Model document is open and active.

'           (3) Specified SolidWorks Design Checker

'               requirements file exists.

'

' Postconditions:

'           (1) SolidWorks Design Checker add-in is loaded.

'           (2) SolidWorks Design Checker checks the active

'               model document as per the requirements file

'               adds the report to the Design Binder.

'

' Possible values for retval are:

'           0 = dsgnchkNOErr

'           1 = dsgnchkReportAlreadyExists

'           2 = dsgnchkCouldNotCreateReportDirectory

'           3 = dsgnchkNoActivedocument

'           4 = dsgnchkStandardFileDoesNotExist

'

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

Option Explicit

Dim swApp As SldWorks.SldWorks

Sub main()

 

    Dim swModel                 As SldWorks.ModelDoc2

    Dim swDCAddIn               As DesignCheckerLib.SWDesignCheck

    Dim strDllFileName          As String

    Dim strExecutablePath       As String

    Dim lStatus                 As Long

    Dim StandardFileName        As String

    Dim ReportFolderName        As String

    Dim retval                  As Long

    Dim AddtoDesignBinder       As Boolean

    Dim OverWriteReport         As Boolean

    Dim CanViewReportOnSave     As Boolean

 

    ' 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 SolidWorks Design Checker DLL exists

    strExecutablePath = swApp.GetExecutablePath

    strDllFileName = strExecutablePath & "\dsgnchk\dsgnchku.dll"

       ' 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. "

                    Debug.Print "Unload the add-in in SolidWorks and then rerun the macro."

            End Select

            

            Exit Sub

        Else

        

            ' DLL was loaded

            ' Get the SolidWorks Design Checker add-in

             Set swDCAddIn = swApp.GetAddInObject("SWDesignChecker.SWDesignCheck")

             If swDCAddIn Is Nothing Then

                Debug.Print "No SolidWorks Design Checker add-in."

                Exit Sub

            End If

        End If

 

    ' SolidWorks Design Checker add-in is loaded

    ' Use the add-in in SolidWorks 2006 and later

    ' Substitute the path and name of your requirements file

    ' and your name for the report

    StandardFileName = "C:\test\aw_hook.swstd" ' Requirements file

    ReportFolderName = "aw_hook" ' Filename for report

    AddtoDesignBinder = True ' Add report to Design Binder

    OverWriteReport = True ' Overwrite any existing report

    CanViewReportOnSave = True ' Display report and save it

    

    ' Run SolidWorks Design Checker on the active model document

    retval = swDCAddIn.RunDesignCheck2(StandardFileName, ReportFolderName, AddtoDesignBinder, OverWriteReport, CanViewReportOnSave)

    Debug.Print retval

    

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:   Run SolidWorks Design Checker 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) 2014 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.