<?xml encoding=”UTF-8″>By Adam Nagy
You may want to get the outer edges of multiple connected faces, i.e. ignore the edges connecting them. In this specific case we’ll get all the tangentially connected faces of the selected face then get the overall outer edges of those.
Each Face has an EdgeLoops collection, and each EdgeLoop has an IsOuterEdgeLoop property which tells us if it contains the edges of the outer border of the given face. Just because it’s an outer edge of the given face it can still be an edge that is connecting two of the faces we are interested in, and if it is then we’ll ignore it.
' Utility function just to check if the collection
' we are using already includes a given object
Function IsInCollection( _
o As Object, coll As ObjectCollection) As Boolean
Dim o2 As Object
For Each o2 In coll
If o2 Is o Then
IsInCollection = True
Exit Function
End If
Next
IsInCollection = False
End Function
' Recursively collect all tangent faces
Sub GetAllTangentiallyConnectedFaces( _
f As Face, faces As ObjectCollection)
Dim f2 As Face
For Each f2 In f.TangentiallyConnectedFaces
If Not IsInCollection(f2, faces) Then
Call faces.Add(f2)
Call GetAllTangentiallyConnectedFaces(f2, faces)
End If
Next
End Sub
' Only check outer edges, and also ignore common
' edges with other faces
Sub GetOuterEdgesOfFaces( _
faces As ObjectCollection, edges As ObjectCollection)
Dim f As Face
For Each f In faces
Dim el As EdgeLoop
For Each el In f.EdgeLoops
If el.IsOuterEdgeLoop Then
Dim e As Edge
For Each e In el.edges
Dim f2 As Face
For Each f2 In e.faces
If (Not f Is f2) And _
(Not IsInCollection(f2, faces)) And _
(Not IsInCollection(e, edges)) Then
Call edges.Add(e)
End If
Next
Next
End If
Next
Next
End Sub
Sub SelectOuterEdgesOfConnectedFaces()
Dim doc As PartDocument
Set doc = ThisApplication.ActiveDocument
Dim f As Face
Set f = doc.SelectSet(1)
Call doc.SelectSet.Clear
Dim tro As TransientObjects
Set tro = ThisApplication.TransientObjects
Dim faces As ObjectCollection
Set faces = tro.CreateObjectCollection
Call GetAllTangentiallyConnectedFaces(f, faces)
Dim edges As ObjectCollection
Set edges = tro.CreateObjectCollection
Call GetOuterEdgesOfFaces(faces, edges)
Call doc.SelectSet.SelectMultiple(edges)
End Sub
The code in action:
Note that in case of the given model all the outer faces are tangentially connected to the initially selected face:



Leave a Reply