Message 1 of 4
Counting "touching" faces by code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Dear,
I am trying to count the number of faces that are touching in the assembly. Currently I use this code, but the result is not satisfying. In the assembly I have a clip placed against the pipe tagent, so only 1 line in the plane is touching the pipe. How can I detect this plane?
' Get the active assembly document and its definition. Dim asmDoc As AssemblyDocument asmDoc = ThisApplication.ActiveDocument Dim oDef As AssemblyComponentDefinition oDef = asmDoc.ComponentDefinition Dim oOccs As New List(Of ComponentOccurrence) For Each oOcc As ComponentOccurrence In oDef.Occurrences If oOcc.BomStructure = BOMStructureEnum.kNormalBOMStructure Or _ oOcc.BomStructure = BOMStructureEnum.kPurchasedBOMStructure Or _ oOcc.BomStructure = BOMStructureEnum.kPhantomBOMStructure Then oOccs.Add(oOcc) End If Next Dim part1 As ComponentOccurrence Dim part2 As ComponentOccurrence Dim x As Integer = 0 Dim oTestString As New List(Of String) For i = 0 To oOccs.Count - 2 part1 = oOccs.item(i) 'sgBox(part1.Name) For Y = i + 1 To oOccs.Count - 1 part2 = oOccs.item(y) MsgBox("Part 1 = " & part1.Name & " | Part 2 = " & part2.Name) ' Get the bodies in part space as transient bodies. Dim transBrep As TransientBRep transBrep = ThisApplication.TransientBRep Dim body1 As SurfaceBody Dim body2 As SurfaceBody body1 = transBrep.Copy(part1.Definition.SurfaceBodies.Item(1)) body2 = transBrep.Copy(part2.Definition.SurfaceBodies.Item(1)) ' Transform the bodies to be in the location represented in the assembly. transBrep.Transform(body1, part1.Transformation) transBrep.Transform(body2, part2.Transformation) ' Imprint the bodies. Dim newBody1 As SurfaceBody Dim newBody2 As SurfaceBody Dim body1OverlapFaces As Faces Dim body2OverlapFaces As Faces Dim body1OverlapEdges As Edges Dim body2OverlapEdges As Edges ThisApplication.TransientBRep.ImprintBodies(body1, body2, True, newBody1, newBody2, _ body1OverlapFaces, body2OverlapFaces, _ body1OverlapEdges, body2OverlapEdges,1) ' TODO: exception mating of bolt/nuts/washers ' TODO: wat met losse onderdelen aanduiding? Negeren? Davit = ook las? ' TODO: recusief met sub assemblies? BOM volgorde? MsgBox("body1OverlapFaces = " & body1OverlapFaces.count) MsgBox("body2OverlapFaces = " & body2OverlapFaces.count) MsgBox("body1OverlapEdges = " & body1OverlapEdges.count) MsgBox("body2OverlapEdges = " & body2OverlapEdges.count) If body1OverlapFaces.Count > 0 Then Dim oString As String = "Las: " & part1.Name & " tegen " & part2.Name oTestString.add(oString) x = x + 1 Else If body1OverlapEdges.Count > 0 Then Dim oString As String = "Las: " & part1.Name & " tegen " & part2.Name oTestString.add(oString) x = x + 1 End If End If Next Next MsgBox("Aantal lassen: " & x) For Each oString As String in oTestString MsgBox(oString) Next
Please kudo if this post was helpfull
Please accept as solution if your problem was solved
Inventor 2014 SP2