Hide Table of Contents

Compare Geometry Example (VB.NET)

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

' This example shows how to use the SOLIDWORKS Utilities API to compare geometries in two part documents.

'

' Preconditions:

'

' 1. Add the SOLIDWORKS Utilities as an add-in

'    (in SOLIDWORKS, click Tools > Add-Ins > SOLIDWORKS Utilities).

' 2. Add the SOLIDWORKS Utilities interop assembly as a reference

'    (right-click on the project in Project Explorer, Add Reference,

'     Browse to <SOLIDWORKS_install_dir>\api\redist\CLR2,

'     select Solidworks.Interop.gtswutilities.dll).

' 3. The specified files exist.

' 4. C:\test\ exists.

'

' Postconditions:

'

' 1. Geometry comparison report, C:\test\Report\gtReportIndex.htm, is created.

' 2. Face and volume comparison statuses display in the Immediate Window.

' 3. Volume comparison part, C:\test\volumeComparison.sldprt, is created.

'

' NOTE: Do not save the parts as they are used in a SOLIDWORKS tutorial.

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

Imports SOLIDWORKS.Interop.sldworks

Imports SOLIDWORKS.Interop.swconst

Imports SOLIDWORKS.Interop.gtswutilities

Imports System

Imports System.Diagnostics

Partial Class SOLIDWORKSMacro

    Sub main()

        Dim swUtil As gtcocswUtilities

        Dim swUtilCompGeom As gtcocswCompareGeometry

        Dim longStatus As gtError_e

        Dim bAddToBinder As Boolean

        Dim bOverwrite As Boolean

        Dim errorCode As Long

        ' Get the SOLIDWORKS Utilities tool interface

        swUtil = swapp.GetAddInObject("Utilities.UtilitiesApp")

        ' Get the CompareGeometry tool

        swUtilCompGeom = swUtil.GetToolInterface(2, errorCode)

        If Not errorCode = gtError_e.gtNOErr Then

            Debug.Print("Error getting compare geometry tool. Inspect gtError_e = " & errorCode & " in the API help.")

        End If

        ' Compare the volumes and faces of the specified part documents

        ' Save the results to a file in the specified path

        bAddToBinder = False

        bOverwrite = True

        Dim file1 As String

        Dim file2 As String

        Dim volDiffStatus As Long

        Dim faceDiffStatus As Long

        file1 = "C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\samples\tutorial\swutilities\bracket_a.sldprt"

        file2 = "C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\samples\tutorial\swutilities\bracket_b.sldprt"

        longStatus = swUtilCompGeom.CompareGeometry3(file1, "", file2, "", gtGdfOperationOption_e.gtGdfFaceAndVolumeCompare, gtResultOptions_e.gtResultSaveReport, "C:\test\Report", bAddToBinder, bOverwrite, volDiffStatus, faceDiffStatus)

        If Not longStatus = gtError_e.gtNOErr Then

            Debug.Print("Error comparing geometries. Inspect gtError_e = " & longStatus & " in the API help.")

        End If

        Call diffStatus("Volume comparison", volDiffStatus)

        Call diffStatus("Face comparison", faceDiffStatus)

        'Save the volume comparison results as a solid part

        longStatus = swUtilCompGeom.SaveCompareVolumeResults("c:\test\volumeComparison")

        ' Perform any necessary clean up

        longStatus = swUtilCompGeom.Close()

    End Sub

    Sub diffStatus(ByVal name As String, ByVal diffCode As gtVolDiffStatusOptionType_e)

        Debug.Print(name)

        Select Case diffCode

            Case gtVolDiffStatusOptionType_e.gtSuccess

                Debug.Print("Succeeded")

            Case gtVolDiffStatusOptionType_e.gtNotPerformed

                Debug.Print("Not performed")

            Case gtVolDiffStatusOptionType_e.gtCanceled

                Debug.Print("Canceled")

            Case gtVolDiffStatusOptionType_e.gtFailed

                Debug.Print("Failed")

            Case gtVolDiffStatusOptionType_e.gtIdenticalParts

                Debug.Print("Identical parts")

            Case gtVolDiffStatusOptionType_e.gtDifferentParts

                Debug.Print("Different parts")

            Case gtVolDiffStatusOptionType_e.gtNoSolidBody

                Debug.Print("No solid body found")

            Case gtVolDiffStatusOptionType_e.gtAlreadySaved

                Debug.Print("Already saved")

        End Select

    End Sub

   

    Public swApp As SldWorks

End Class



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:   Compare Geometry Example (VB.NET)
*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) 2015 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.