Hi @GeorgK,
Here's the beginnings of a rule I worked up last week for this.
So far all it does is create workpoints at the boundingbox centre for each top-level occurrence. The next logical step would (I think) be to "explode" these points apart by a set distance.
Then of course it would need to be made to work in the Presentation environment and translate those exploded positions into Tweaks.
Which is some ways away I think.
Anyways, here's my code so far:
Sub Main()
Dim points As New List(Of KeyValuePair(Of String, Point))
Dim thisAssy As AssemblyDocument = ThisApplication.ActiveDocument
Dim originMatrix As Matrix = ThisApplication.TransientGeometry.CreateMatrix
Dim destinationMatrix As Matrix = ThisApplication.TransientGeometry.CreateMatrix
Dim originPoint As WorkPoint = thisAssy.ComponentDefinition.WorkPoints.Item(1)
originPoint.Visible = True
Dim occurrenceYNormal As UnitVector = Nothing
For Each occ As ComponentOccurrence In thisAssy.ComponentDefinition.Occurrences
Dim oTransform As Matrix = occ.Transformation
Dim occDatum As WorkPoint = Nothing
If TypeOf (occ.Definition.Document) Is PartDocument Then
Dim IsAPart As PartDocument = occ.Definition.Document
Dim partXYWorkPlane As WorkPlane = IsAPart.ComponentDefinition.WorkPlanes(1)
Dim normalPlane As Plane = partXYWorkPlane.Plane
occurrenceYNormal = ThisApplication.TransientGeometry.CreateUnitVector(normalPlane.Normal.X, normalPlane.Normal.Y, normalPlane.Normal.Z)
occDatum = IsAPart.ComponentDefinition.WorkPoints(1)
occDatum.Visible = False
Else
Dim IsAnAssembly As AssemblyDocument = occ.Definition.Document
Dim assyXYWorkPlane As WorkPlane = IsAnAssembly.ComponentDefinition.WorkPlanes(1)
Dim normalPlane As Plane = assyXYWorkPlane.Plane
occurrenceYNormal = ThisApplication.TransientGeometry.CreateUnitVector(normalPlane.Normal.X, normalPlane.Normal.Y, normalPlane.Normal.Z)
occDatum = IsAnAssembly.ComponentDefinition.WorkPoints(1)
occDatum.Visible = False
End If
Dim compdef As ComponentDefinition = occ.Definition
originMatrix.SetTranslation(originPoint.Point.VectorTo(occDatum.Point))
Dim originYVector As Vector = ThisApplication.TransientGeometry.CreateVector(0, 1, 0)
originMatrix.SetToRotateTo(originYVector, occurrenceYNormal.AsVector())
Dim tmpPoint As Point = getBoxCentreFromOccurrence(occ)
points.Add(New KeyValuePair(Of String, Point)(occ.Name, tmpPoint))
Next
For Each pnt As KeyValuePair(Of String, Point) In points
Dim point As Point = pnt.Value
Dim wp As WorkPoint = thisAssy.ComponentDefinition.WorkPoints.AddFixed(ThisApplication.TransientGeometry.CreatePoint(point.X, point.Y, point.Z))
wp.Name = "Work Point: " & pnt.Key
Next
End Sub
Function getBoxCentreFromComponentDefinition (thiscompDef As ComponentDefinition) As Point
Dim centrepoint As Point = ThisApplication.TransientGeometry.CreatePoint((thiscompDef.RangeBox.MaxPoint.X - thiscompDef.RangeBox.MinPoint.X) / 2,
(thiscompDef.RangeBox.MaxPoint.Y - thiscompDef.RangeBox.MinPoint.Y) / 2,
(thiscompDef.RangeBox.MaxPoint.Z - thiscompDef.RangeBox.MinPoint.Z) / 2)
Return centrepoint
End Function
Function getBoxCentreFromOccurrence(thisocc As ComponentOccurrence) As Point
Dim centrepoint As Point = ThisApplication.TransientGeometry.CreatePoint((thisocc.RangeBox.MaxPoint.X - thisocc.RangeBox.MinPoint.X) / 2 + thisocc.RangeBox.MinPoint.X,
(thisocc.RangeBox.MaxPoint.Y - thisocc.RangeBox.MinPoint.Y) / 2 + thisocc.RangeBox.MinPoint.Y,
(thisocc.RangeBox.MaxPoint.Z - thisocc.RangeBox.MinPoint.Z) / 2 + thisocc.RangeBox.MinPoint.Z)
Return centrepoint
End Function
Incidentally, this forms part of my iLogic github repo here: https://github.com/AlexFielder/iLogic
Maybe I'm overthinking it (It has been known to happen) so please, anyone who has a better idea do speak up.
🙂
PS. @chandra.shekar.g I perhaps wasn't clear in my suggestion to speak to your team; I meant to ask them if the "explode" javascript function available in the Autodesk web viewer could be repurposed into iLogic to save us the trouble? I had a look around myself to see if I could find what it was based upon but to no avail, although I have one other avenue left to explore.