Display range box of componenets in assembly context

By Xiaodong Liang

The RangeBox is a rectangular box that is guaranteed to enclose this object. If you access the range in the assembly context, you can use ComponentOccurrence.RangeBox without proxy because this has been transformed in the assembly context. The following code assumes there is a top assembly which has some sub assemblies. The sub assemblites are placed with different rotations intentionally. It gets the rangebox of each component and draws a box with transparent appearance. Their locations are in the context of the top assembly. You need to go to the "Appearance Browser" and add the "Clear" appearance to the document before running the code. Of course, you can also use API to add the appearance.

Sub drawComRange()

Dim oAssDoc As AssemblyDocument

Set oAssDoc = ThisApplication.ActiveDocument

Dim localAsset As Asset

Set localAsset = oAssDoc.Assets.Item("Clear")

Dim oCompDef As ComponentDefinition

Set oCompDef = oAssDoc.ComponentDefinition

Dim oTransientBRep As TransientBRep

Set oTransientBRep = ThisApplication.TransientBRep

On Error Resume Next

Dim oClientGraphics As ClientGraphics

Set oClientGraphics = oCompDef.ClientGraphicsCollection.Item("Sample3DGraphicsID")

If Err.Number = 0 Then

On Error GoTo 0

oClientGraphics.Delete

ThisApplication.ActiveView.Update

Err.Clear

Exit Sub

End If

Set oClientGraphics = oCompDef.ClientGraphicsCollection.Add("Sample3DGraphicsID")

Dim oSurfacesNode As GraphicsNode

Set oSurfacesNode = oClientGraphics.AddNode(1)

oSurfacesNode.Appearance = localAsset

Dim oOcc As ComponentOccurrence

For Each oOcc In oAssDoc.ComponentDefinition.Occurrences

Dim oRB As Box

Set oRB = oOcc.RangeBox

Dim oBody As SurfaceBody

Set oBody = oTransientBRep.CreateSolidBlock(oRB.Copy())

‘ Create client graphics based on the transient body

Dim oSurfaceGraphics As SurfaceGraphics

Set oSurfaceGraphics = oSurfacesNode.AddSurfaceGraphics(oBody)

Next

oSurfacesNode.Appearance = localAsset

ThisApplication.ActiveView.Update

End Sub

 

image

 

 

image

<

p style=”margin: 0cm 0cm 0pt” class=”MsoNormal”>


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading