Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
JhoelForshav
in reply to: WCrihfield

Hi @shiftctrl.io 

If the model is an assembly containing only the 5 panels as component occurrences I thought of an approach that doesn't require you to select any face to begin with.

I made a simple iLogic rule to test it and it works as expected :slightly_smiling_face:

 

Sub Main
Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oCoM As Point = oAsm.ComponentDefinition.MassProperties.CenterOfMass
Dim oFaces As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
For Each oOcc As ComponentOccurrence In oAsm.ComponentDefinition.Occurrences
	Dim oFaceProx As FaceProxy
	Dim oDist As Double = 0
	Dim closestFace As FaceProxy
	For Each oFace In oOcc.Definition.SurfaceBodies(1).Faces
		Call oOcc.CreateGeometryProxy(oFace, oFaceProx)
		If oDist = 0 Then
			oDist = oFaceProx.GetClosestPointTo(oCoM).VectorTo(oCoM).Length
			closestFace = oFaceProx
		Else
			Dim thisDist As Double = oFaceProx.GetClosestPointTo(oCoM).VectorTo(oCoM).Length
			If thisDist < oDist
				oDist = thisDist
				closestFace = oFaceProx
			End If
		End If

	Next
	oFaces.Add(closestFace)
Next
For Each oFace As FaceProxy In oFaces
	AddWorkPlaneInAssembly(oAsm, oFace, 0)
Next

End Sub
Sub AddWorkPlaneInAssembly(oAsm As AssemblyDocument, oFace As Object, oOffset As Double)
	'Add Fixed plane (only way to add a plane in assembly environment)
	Dim oDef As AssemblyComponentDefinition = oAsm.ComponentDefinition
	Dim oOriginPnt As Point
	Dim oXaxis, oYaxis As UnitVector
	oOriginPnt = ThisApplication.TransientGeometry.CreatePoint(0, 0, 0)
	oXaxis = ThisApplication.TransientGeometry.CreateUnitVector(1, 0, 0)
	oYaxis = ThisApplication.TransientGeometry.CreateUnitVector(0, 1, 0)
	Dim oPlane As WorkPlane = oDef.WorkPlanes.AddFixed(oOriginPnt, oXaxis, oYaxis)
	'Constrain the plane
	oPlane.AutoResize = True
	oDef.Constraints.AddFlushConstraint(oFace, oPlane, oOffset)
	oPlane.AutoResize = False
End Sub

The code uses the assemblys center of gravity to get a point inside the box. For each occurrence in the assembly it then finds the closest face to that point. Then it takes those faces and creates workplanes on them.

 

Before running iLogic-rule:

1bild.PNG

And after:

2bild.PNG