Hide Table of Contents

Check Interference using IAssemblyDoc::ToolsCheckInterference2 Example (VBA)

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

'----------------------------------------------------------
' Preconditions:
' 1. Open a fully resolved assembly that contains at least
'    two interfering components.
' 2. Select at least two interfering components.
' 3. Open the Immediate window.
'
' Postconditions:
' 1. Selects the interfering faces.
' 2. Examine the graphics area and Immediate window, then
'    press F5.
' 3. Selects the interfering components.
' 4. Examine the graphics area and Immediate window, then
'    press F5.
'----------------------------------------------------------
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)
    Debug.Print "Number of selected components: " & nSelCount
    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 "      Component face[" & i & "] = " & swComp.Name2
            bRet = swEnt.Select4(True, swSelData): Debug.Assert bRet
        Next i
        ' Interfering faces selected        
        Stop
        ' Examine the graphics area and Immediate window, then
        ' press F5 to continue
    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 "    Component [" & i & "] = " & swComp.Name2
            bRet = swComp.Select2(True, 0): Debug.Assert bRet
        Next i
        ' Interfering components selected        
        Stop
        ' Examine the graphics area and Immediate window, then
        ' press F5 to continue
        
    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) 2018 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.