Hide Table of Contents

Check Interference using IAssemblyDoc::ToolsCheckInterference2 Example (VBA)

This example shows how to check an assembly for interference using IAssemblyDoc::ToolsCheckInterference2.

 

NOTE: It is recommended that you step through this macro in the debugger, especially in the sections where the interfering faces and components are highlighted or selected.

 

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

'

' Preconditions:

'       (1) Assembly is open.

'       (2) Assembly contains at least two parts.

'       (3) At least two components or component entities are selected.

'       (4) Assembly is fully resolved.

'

' Postconditions:

'       (1) Any interfering faces are selected and the macro pauses.

'       (2) Any interfering components are selected and the macro pauses.

'

' NOTE: If components touch and coincident faces are not considered

'       to be interfering, then IAssemblyDoc::ToolsCheckInterferenc2

'       returns an empty array of faces. However,

'       IAssemblyDoc::ToolsCheckIntererence2 returns an array of

'       components for components that touch.

'

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

Option Explicit

Sub main()

    Const bCoincidentInterference   As Boolean = False

 

    Dim swApp                       As SldWorks.SldWorks

    Dim swModel                     As SldWorks.ModelDoc2

    Dim swAssy                      As SldWorks.AssemblyDoc

    Dim swSelMgr                    As SldWorks.SelectionMgr

    Dim CompArray()                 As SldWorks.Component2

    Dim swSelData                   As SldWorks.SelectData

    Dim vCompArray                  As Variant

    Dim vIntCompArray               As Variant

    Dim vIntFaceArray               As Variant

    Dim swFace                      As SldWorks.face2

    Dim swEnt                       As SldWorks.entity

    Dim swComp                      As SldWorks.Component2

    Dim i                           As Long

    Dim nSelCount                   As Long

    Dim bRet                        As Boolean

    

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swAssy = swModel

    Set swSelMgr = swModel.SelectionManager

    Set swSelData = SwSelMgr.CreateSelectData

    

    Debug.Print "File = " & swModel.GetPathName    

 

    nSelCount = swSelMgr.GetSelectedObjectCount

    ReDim CompArray(nSelCount - 1)

    

    For i = 0 To (nSelCount - 1)

        Set CompArray(i) = swSelMgr.GetSelectedObjectsComponent2(i + 1)

        

        Debug.Print "Comp[" + i + "] = " + CompArray(i).Name2

    Next i

    vCompArray = CompArray

    

    swAssy.ToolsCheckInterference2 nSelCount, (vCompArray), bCoincidentInterference, vIntCompArray, vIntFaceArray

            

    If (IsEmpty(vIntCompArray) = True) And (IsEmpty(vIntFaceArray) = True) Then

        Debug.Print "  No contact"

        Exit Sub

    End If

 

If Not IsEmpty(vIntFaceArray) Then

        Debug.Print "  " & UBound(vIntFaceArray) + 1 & " Faces interfere!"

    

        swModel.ClearSelection2 True

        For i = 0 To UBound(vIntFaceArray)

            Set swFace = vIntFaceArray(i)

            Set swEnt = swFace

            Set swComp = swEnt.GetComponent

            

            Debug.Print "    CompFace[" & i & "] = " & swComp.Name2

            

            bRet = swEnt.Select4(True, swSelData): Debug.Assert bRet

        Next i

        ' Interfering faces selected

        Stop

    Else

        Debug.Assert Not IsEmpty(vIntCompArray)

        Debug.Assert False = bCoincidentInterference

        

        Debug.Print "  Faces touch but not checking for coincident interference!"

    End If

    

    If Not IsEmpty(vIntCompArray) Then

        Debug.Print "  " & UBound(vIntCompArray) + 1 & " Components interfere!"

    

        swModel.ClearSelection2 True

        For i = 0 To UBound(vIntCompArray)

            Set swComp = vIntCompArray(i)

            

            Debug.Print "    Comp[" & i & "] = " & swComp.Name2

            

            bRet = swComp.Select2(True, 0): Debug.Assert bRet

        Next i

        ' Interfering components selected

        Stop

    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:   Check Interference using AssemblyDoc::ToolsCheckInterference2 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) 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.