Check if Face is along the RangeBox of a part

Check if Face is along the RangeBox of a part

C_Haines_ENG
Collaborator Collaborator
294 Views
4 Replies
Message 1 of 5

Check if Face is along the RangeBox of a part

C_Haines_ENG
Collaborator
Collaborator

Is there an easy way to check if a face is "along" the rangebox of a part. In essence Id get the rangebox of a part and then cycle through all faces to get the ones on the very outside of the part. 

0 Likes
Accepted solutions (1)
295 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @C_Haines_ENG.  It is difficult to know how to answer that.  There is no association or 'ID' between a transient Box and the faces of a body.  Also, a flat, rectangular face will have 4 edges, and each edge can be pointing in a different direction (up on one side vs down on the other ; left along top vs right along bottom), so the 'along' term is confusing.  The face only point outward, away from the solid material.

 

Maybe if you described the 'bigger picture', we could understand the overall challenge better.  For instance, are you just looking for the 'outermost' faces (the faces actually touching the range box), and wanting to skip over all interior faces (faces not touching the range box)?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

C_Haines_ENG
Collaborator
Collaborator

Yes, I just want all faces touching the range box. 

 

BIG PICTURE, is I want the face closest to a point on the solid that is along the outside face. Eventually I need the closest face at the ends of the length of the part as well. 

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor
Accepted solution

Hi @C_Haines_ENG.  That is a tough one.  Another important specification here would be whether you need this 'RangeBox' to be aligned with the model's origin Axes or not.  The regular RangeBox, and also the newer PreciseRangeBox properties, both return a Box object that is always aligned with the model's origin axes, whether the actual model geometry is or not.  But there is also the OrientedMinimumRangeBox, which returns a OrientedBox, which may not be aligned with the origin axes, but may be a more accurate bounding box of the actual geometry.

 

I would suggest creating a transient BRep copy of the bounding box, as a transient SurfaceBody.  Then iterate through its 6 flat faces, for comparing with the faces of your model.  This could potentially include a lot of iterations.  Iterate through every normal body, every face of each body, and only really inspect the 'flat' faces.  If those 'normal' flat faces are 'co-planar' to any of the transient body's faces, then it is considered an 'outer most face'.  As a test, here is an example iLogic rule doing this process, and using a HighLightSet to show you which faces are found to meet that condition.

Sub Main
	Dim oInvApp As Inventor.Application = ThisApplication
	Dim oDoc As Inventor.Document = oInvApp.ActiveDocument
	If (Not TypeOf oDoc Is AssemblyDocument) AndAlso (Not TypeOf oDoc Is PartDocument) Then Return
	Dim oCD As Inventor.ComponentDefinition = oDoc.ComponentDefinition
	'Dim oRangeBox As Inventor.Box = oCD.RangeBox
	Dim oRangeBox As Inventor.Box = oCD.PreciseRangeBox 'new in 2022
	If oRangeBox Is Nothing OrElse oRangeBox.MinPoint.IsEqualTo(oRangeBox.MaxPoint) Then Return
	Dim oTG As Inventor.TransientGeometry = oInvApp.TransientGeometry
	Dim oTBRep As Inventor.TransientBRep = oInvApp.TransientBRep
	Dim oTBody As SurfaceBody = oTBRep.CreateSolidBlock(oRangeBox)
	Dim oOuterFaces As New List(Of Inventor.Face)
	For Each oBody As SurfaceBody In oCD.SurfaceBodies
		For Each oFace As Face In oBody.Faces
			If (Not TypeOf oFace.Geometry Is Inventor.Plane) Then Continue For
			Dim oFacePlane As Inventor.Plane = oFace.Geometry
			'now check if this is co-planar to any of the faces of the RangeBox
			For Each oTFace As Face In oTBody.Faces
				If (Not TypeOf oTFace.Geometry Is Inventor.Plane) Then Continue For
				Dim oTFacePlane As Inventor.Plane = oTFace.Geometry
				If oFacePlane.IsCoplanarTo(oTFacePlane, 0.001) Then
					oOuterFaces.Add(oFace)
				End If
			Next oTFace
		Next oFace
	Next oBody
	If oOuterFaces.Count = 0 Then
		MessageBox.Show("No outer faces found!", "No Outer Faces Found", _
		MessageBoxButtons.OK, MessageBoxIcon.Information)
	Else
		Dim oHLS As HighlightSet = oDoc.CreateHighlightSet()
		For Each oOuterFace As Face In oOuterFaces
			oHLS.AddItem(oOuterFace)
		Next oOuterFace
		MessageBox.Show("Review highlighted outer faces.", "Outer Faces Highlighted", _
		MessageBoxButtons.OK, MessageBoxIcon.Information)
		oHLS.Clear
	End If
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 5

C_Haines_ENG
Collaborator
Collaborator

This is a great solution, I definitely wobbled my way through this by copying the range box and shrinking it by 0.01 cm and just finding every face that was not contained by the Surface Body but I will switch to your method!

0 Likes