08-13-2020
07:34 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
08-13-2020
07:34 AM
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 ![]()
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:
And after:
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website