AnsweredAssumed Answered

FACES COINCIDENT IN INTERFERENCE DETECTION?

Question asked by roberto gennari on Oct 26, 2015

Hallo,

my requirement is to coloring of green all the faces that have a matching contact between them, NOT an interference.

To do this I edited a macro for interference checking.

the macro works but not very well, in fact I color also faces that should not?

 

Can someone help me overcome my mistakes?

 

Thanks

 

This is my macro:

 

 

Option Explicit

    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
    Dim vFaceProp                   As Variant
    Dim swModelDocExt As SldWorks.ModelDocExtension

 

Sub main()

 

    Const bCoincidentInterference   As Boolean = True


    '
    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)
    Next i
    '
    vCompArray = CompArray
    '
    swAssy.ToolsCheckInterference2 nSelCount, (vCompArray), bCoincidentInterference, vIntCompArray, vIntFaceArray
    '
    If (IsEmpty(vIntCompArray) = True) And (IsEmpty(vIntFaceArray) = True) Then
        Debug.Print "  No contact"
        MsgBox "Nessun contatto, l'applicazione esce"
        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(False, swSelData): Debug.Assert bRet
                    vFaceProp = swEnt.MaterialPropertyValues
                            'vFaceProp = swModel.MaterialPropertyValues: Debug.Assert Not IsEmpty(vFaceProp)
                            vFaceProp = swModel.MaterialPropertyValues
        'bRet = swModel.SelectedFaceProperties(RGB(0, 255, 0), vFaceProp(3), vFaceProp(4), vFaceProp(5), vFaceProp(6), vFaceProp(7), vFaceProp(8), False, ""): Debug.Assert bRet 'VIOLA EROSIONE
                            bRet = swModel.SelectedFaceProperties(RGB(0, 255, 0), vFaceProp(3), vFaceProp(4), vFaceProp(5), vFaceProp(6), vFaceProp(7), vFaceProp(8), False, "")
            Next i
   
        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
    End If
    '
End Sub

Outcomes