Run SolidWorks Design Checker Example (VB.NET)
This example shows how to check the active document using the SolidWorks
Design Checker API.
'--------------------------------------------
'
' Preconditions:
' 1.
Load the SolidWorks Design Checker add-in
' (click
Tools > Add-ins > SolidWorks Design
Checker).
' 2
Create
c:\test if needed.
' 3.
Create a SolidWorks Design Checker standards file using
' the
SolidWorks Design Checker tutorial
' and
saving the standards file to c:\test
(click
' Tools > Design
Checker > Build Checks > Design Checker
' Tutorial
to open the tutorial and perform the steps
' through
"Building the Design Requirements-2").
' 4.
Reference the SolidWorks Design Checker primary interop assembly
' (in
the IDE, right-click the project name, select
' Add Reference,
click the Browse tab, navigate to the
' <SolidWorks_install_dir>\api\redist
folder and
' select
SolidWorks.Interop.dsgnchk.dll).
' 5.
Open the Immediate window.
' 6.
Run the macro.
'
' Postconditions:
' 1.
The Design Binder folder is shown in the FeatureManager design tree.
' 2.
SolidWorks Design Checker checks the active
' model
document as per the standards file, adds the
' Post-Correction
Result.drp and Pre-Correction Result.drp
' reports
to the Design Binder and the SWCDReport.xml reports to the
' c:\test\Food Processor_mm_dd_yyyy_hr_min\Post-Correction
Result and
' c:\test\Food Processor_mm_dd_yyyy_hr_min\Pre-Correction
Result folders.
' 3.
To verify that these reports were added
' to
the Design Binder, examine the Design Binder in the
' FeatureManager
design tree. To verify that the folder and reports
' were
created, examine c:\test.
'
' NOTE: Because this drawing document is used by a SolidWorks
' tutorial,
do not save any changes when closing the
' document.
'
'---------------------------------------------
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports SolidWorks.Interop.dsgnchk
Imports System
Imports System.Diagnostics
Partial Class SolidWorksMacro
Public
Sub main()
Dim
swDCAddIn As SWDesignCheck
Dim
StandardFileName As String
Dim
ReportFolderName As String
Dim
retValue As Long
Dim
AddtoDesignBinder As Boolean
Dim
OverWriteReport As Boolean
Dim
warnings As Long
Dim
errors As Long
Dim
AutoCorrect As Boolean
'
Get the SolidWorks Design Checker add-in
swDCAddIn
= swApp.GetAddInObject("SWDesignChecker.SWDesignCheck")
If
swDCAddIn Is Nothing Then
Debug.Print("No
SolidWorks Design Checker add-in.")
Exit
Sub
End
If
'
Show the Design Binder in the FeatureManager design tree
swApp.SetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swFeatureManagerDesignBinderVisibility,
swAutoHideShowResponse_e.swAutoHideShowResponse_Show)
'
Open the drawing document to check
swApp.OpenDoc6("C:\Program Files\SolidWorks
Corp\SolidWorks\samples\tutorial\advdrawings\FoodProcessor.slddrw",
swDocumentTypes_e.swDocDRAWING, swOpenDocOptions_e.swOpenDocOptions_Silent,
"", errors, warnings)
'
Requirements file
StandardFileName
= "C:\test\tutorial.swstd"
'
Filename for report
ReportFolderName
= "c:\test\Food Processor"
'
Add report to Design Binder
AddtoDesignBinder
= True
'
Overwrite any existing report
OverWriteReport
= True
'
Autocorrect all failures
AutoCorrect
= True
'
Run SolidWorks Design Checker on the active drawing document
retValue
= swDCAddIn.RunDesignCheck4(StandardFileName,
ReportFolderName, AddtoDesignBinder, OverWriteReport, AutoCorrect)
Select
Case retValue
Case
0
Debug.Print("No
errors.")
Case
1
Debug.Print("Report
already exists.")
Case
2
Debug.Print("Could
not create report directory.")
Case
3
Debug.Print("No
active document.")
Case
4
Debug.Print("Standards
file does not exist.")
End
Select
End
Sub
'''
<summary>
'''
The SldWorks swApp variable is pre-assigned for you.
'''
</summary>
Public
swApp As SldWorks
End Class