Compare Documents Example (VBA)
This example shows how to compare the volumes of two parts and then
save the results of the comparison as a solid part using the SOLIDWORKS
Utilities API.
'--------------------------------------------
'
' Preconditions:
' (1)
The files c:\test\test.sldprt
and
' c:\test\thinellipse.sldprt
exist.
' (2)
The path c:\test\report\gtReport
exists.
'
' Postconditions:
' (1)
Report is created in c:\test\report.
' (2)
The file Volume Comparison of ellipse
' and thinellipse.sldprt is created.
'
'---------------------------------------------
Option Explicit
Sub main()
Dim
swapp As
SldWorks.SldWorks
Dim
swUtil As
SWUtilities.gtcocswUtilities
Dim
swUtilCompdoc As
SWUtilities.gtcocswCompareDocument
Dim
longStatus As
Long
Dim
bAddToBinder As
Boolean
Dim
bOverwrite As
Boolean
'
Connect to SOLIDWORKS
Set
swapp = Application.SldWorks
'
Get the SOLIDWORKS Utilities interface
Set
swUtil = swapp.GetAddInObject("Utilities.UtilitiesApp")
'
Set the SOLIDWORKS Utilities tool to Compare Documents
Set
swUtilCompdoc = swUtil.GetToolInterface(gtSwToolCompDocs,
0)
'
Compare the volumes of the specified part documents; do not show the Results
'
dialog box, but do save the results to a file in the specified path
bAddToBinder
= False
bOverwrite
= True
longStatus
= swUtilCompdoc.CompareDocument2("c:\test\ellipse.sldprt",
"", "c:\test\thinellipse.sldprt", "", gtCodVolumeCompare,
gtResultSaveReport, "C:\test\Report", bAddToBinder, bOverwrite)
'
Save the volume comparison results as a SOLIDWORKS part document
longStatus
= swUtilCompdoc.SaveCompareVolumeResults("c:\test")
'
Perform any necessary clean up
longStatus
= swUtilCompdoc.Close()
End Sub