Counting "touching" faces by code

Counting "touching" faces by code

Jef_E
Collaborator Collaborator
469 Views
3 Replies
Message 1 of 4

Counting "touching" faces by code

Jef_E
Collaborator
Collaborator

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

 

 

Knipsel.PNG 



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
470 Views
3 Replies
Replies (3)
Message 2 of 4

JelteDeJong
Mentor
Mentor

i found an post on a simmular topic (Find Touching Area of Two Coplanar Faces) but it looks to difficult for me.

Maby this simpler solutions work for you:

  1. You can try to use the  collision detection from inventor.
  2. The other option is to look at all the constraints. (i guess that your welds are always constarint.) if the offset of a mate or tangent constarint is 0 then you problay need to weld. see iLogic script below:
Dim doc As AssemblyDocument = ThisDoc.Document
Dim constarint = doc.ComponentDefinition.Constraints.Item(1)

For Each constraint As AssemblyConstraint In doc.ComponentDefinition.Constraints
    If (constraint.Type = ObjectTypeEnum.kMateConstraintObject) Then
        Dim mate As MateConstraint = constraint
        If (mate.Offset.Value < 0.0001) Then
            MsgBox(String.Format("occurence {0} is toching occurence {1}",
                            mate.OccurrenceOne._DisplayName, mate.OccurrenceTwo._DisplayName))
        End If
    ElseIf (constraint.Type = ObjectTypeEnum.kTangentConstraintObject) Then
        Dim mate As TangentConstraint = constraint
        If (mate.Offset.Value < 0.0001) Then
            MsgBox(String.Format("occurence {0} is toching occurence {1}",
                            mate.OccurrenceOne._DisplayName, mate.OccurrenceTwo._DisplayName))
        End If
    End If
Next

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 4

Jef_E
Collaborator
Collaborator

- suggestion 1 Will not work, this method adds extrude features, and not all faces are planar.

1) Colision detection may work havent heard of it. we use inventor 2014, is this available?

2) Also is reling on the fact that a constraint needs to be in place in order to have a check. Skeleton models that use ground and root are not considered and thus not fool proof;

 

My method is working but not taking tangent plane to round into  account all other matching faces are considered...



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

Here are a couple of links explaining the similar features built into Inventor.

About Interference between Components 

Detect contact between assembly components 

I don't recall exactly when these abilities / tools were added into Inventor.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes