FaceShell OrientedRangeBox

FaceShell OrientedRangeBox

J-Camper
Advisor Advisor
814 Views
4 Replies
Message 1 of 5

FaceShell OrientedRangeBox

J-Camper
Advisor
Advisor

I'm trying to upgrade the sub routine below to used the OrientedMinimumRangeBox Method on Each FaceShell of a Multi-FaceShell SurfaceBody:

Function BuildDescription(pDef As PartComponentDefinition, bIndex As Integer) As String
	Dim Result As String = Nothing
	Dim BoxCollection As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
	Dim oSolid As SurfaceBody = pDef.SurfaceBodies.Item(bIndex)
	If oSolid.FaceShells.Count > 1
		Logger.Trace("Multi body: " & oSolid.FaceShells.Count & " only works with normal rangebox")
		For Each fs As FaceShell In oSolid.FaceShells
			If fs.IsVoid Then Continue For
			Dim DeltaX, DeltaY, DeltaZ As Double
			Dim fsBox As Box = fs.RangeBox
			DeltaX = fsBox.MaxPoint.X - fsBox.MinPoint.X
			DeltaY = fsBox.MaxPoint.Y - fsBox.MinPoint.Y
			DeltaZ = fsBox.MaxPoint.Z - fsBox.MinPoint.Z
'			Dim AddRoughString As String = FormulateString(DeltaX, DeltaY, DeltaZ)
'			Result += AddRoughString
		Next

	Else If oSolid.FaceShells.Count = 1
		Logger.Trace("Single")
		BoxCollection.Add(oSolid.OrientedMinimumRangeBox)
	End If
	Logger.Trace("Collected: " & BoxCollection.Count)
'	For Each ItemRangeBox As OrientedBox In BoxCollection
'		Dim AddString As String = FormulateString(ItemRangeBox.DirectionOne.Length, ItemRangeBox.DirectionTwo.Length, ItemRangeBox.DirectionThree.Length)
'		Result += AddString
'	Next
	Return Result
End Function

Don't worry about the commented out lines, they work and don't need to be tested.  I just want all the FaceShells to put an OrientedMinimumRangeBox Into the BoxCollection to be processed at the bottom.

 

Current workflow up to this point:

  • user selects ComponentOccurrence From Main Assembly
  • user selects a SurfaceBody from List
  • The above Function is called with ComponentDefinition and Index of SurfaceBody

I have tried several processes that all failed, so I'm reaching out for help.

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

J-Camper
Advisor
Advisor

Okay, I got it working except It has issues with bodies AffectedBy Combine(Cut) Features?  I'm not sure why, but maybe there is another way that won't fail?

 

Here is the current state:

Function BuildDescription(pDef As PartComponentDefinition, oSolid As SurfaceBody) As String
	Dim Result As String = Nothing
	Dim BoxCollection As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
	If oSolid.FaceShells.Count > 1
		Logger.Trace("Multi body: " & oSolid.FaceShells.Count)
		Dim TransBody As SurfaceBody = ThisApplication.TransientBRep.Copy(oSolid)
		For Each fs As FaceShell In  TransBody.FaceShells
			Dim keepFaces As FaceCollection = ThisApplication.TransientObjects.CreateFaceCollection()
			'Collect Faces To Keep
			For Each f As Face In fs.Faces
				keepFaces.Add(f)
			Next
			


'Delete All Faces Except those you want to keep [False Boolean]
			ThisApplication.TransientBRep.DeleteFaces(keepFaces, False) 'Has Issues with Combine(Cut) Features for some reason???
			


'Get OrientedRangeBox
			BoxCollection.Add(TransBody.OrientedMinimumRangeBox)
			'Reset Transient Body
			TransBody = ThisApplication.TransientBRep.Copy(oSolid)
		Next

	Else If oSolid.FaceShells.Count = 1
		'Logger.Trace("Single")
		BoxCollection.Add(oSolid.OrientedMinimumRangeBox)
	End If
	Logger.Trace("Collected: " & BoxCollection.Count)
	For Each ItemRangeBox As OrientedBox In BoxCollection
		Dim AddString As String = FormulateString(ItemRangeBox.DirectionOne.Length, ItemRangeBox.DirectionTwo.Length, ItemRangeBox.DirectionThree.Length)
		Result += AddString
	Next
	Return Result
End Function

 

Can anyone get this to work for a multi-FaceShell SurfaceBody AffectedBy a Combine(Cut) Feature?

0 Likes
Message 3 of 5

J-Camper
Advisor
Advisor
Accepted solution

I have abandoned the delete faces workflow, in favor of a build SurfaceBodyDefinition from FaceShell Properties workflow.  It works where the previous workflow was failing [bodies affected by Combine(Cut).

 

I'm now using "ThisApplication.TransientBRep.CreateSurfaceBodyDefinition" method to build a definition based on the FaceShell's face & EdgleLoop Properties.  This is superior to the delete face workflow.

0 Likes
Message 4 of 5

dg2405
Advocate
Advocate

Have you an expample how to do that?

0 Likes
Message 5 of 5

J-Camper
Advisor
Advisor

@dg2405,

 

This is the main process for each SolidBody:

For Each fs As FaceShell In oSolid.FaceShells
	'Define Objects to create transient copy
	Dim sbDef As SurfaceBodyDefinition = ThisApplication.TransientBRep.CreateSurfaceBodyDefinition 
	Dim lumpDef As LumpDefinition = sbDef.LumpDefinitions.Add()
	Dim fsDef As FaceShellDefinition = lumpDef.FaceShellDefinitions.Add()
	'Start to fill Definition
	For Each f As Face In fs.Faces
		If f.SurfaceType <> SurfaceTypeEnum.kEllipticalCylinderSurface
			Dim fDef As FaceDefinition = fsDef.FaceDefinitions.Add(f.Geometry, f.IsParamReversed)
			Dim elDef As EdgeLoopDefinition = fDef.EdgeLoopDefinitions.Add()
			For Each ed As Edge In f.EdgeLoops.Item(1).Edges
				elDef.EdgeUseDefinitions.Add(sbDef.EdgeDefinitions.Add(sbDef.VertexDefinitions.Add(ed.StartVertex.Point), sbDef.VertexDefinitions.Add(ed.StopVertex.Point), ed.Geometry), ed.IsParamReversed)
			Next
		Else If f.SurfaceType = SurfaceTypeEnum.kEllipticalCylinderSurface
			'Logger.Debug("Skipping " & CType(f.SurfaceType, SurfaceTypeEnum).ToString & " for now")
		End If
	Next
	'Logger.Trace("Attempt Body creation")
	Dim oErrors As NameValueMap
	Dim TransBody As SurfaceBody = sbDef.CreateTransientSurfaceBody(oErrors)
Next

[oSolid is a Surfacebody that has volume and more than 1 FaceShell]

 

The transient SurfaceBody "TransBody" can then return the OrientedRangeBox Property.  I was getting errors with some combine cut faces that were affected by elliptical curve geometry, so I ignore them in my transient body.  They were non-impactful surfaces for my needs so  it was not something i spent time to fully investigate.

 

Let me know if you have any questions, or if something is not working for you