Explode a Block Reference

AutoCAD ActiveX

Explode a Block Reference

Use the Explode method to break a block reference. By exploding a block ref-erence, you can modify the block or add to or delete the objects that define it.

Display the results of an exploded block reference

This example creates a block and adds a circle to the definition of the block. The block is then inserted into the drawing as a block reference. The block reference is then exploded, and the objects resulting from the explode process are displayed along with their object types.

Sub Ch10_ExplodingABlock()
 ' Define the block
 Dim blockObj As AcadBlock
 Dim insertionPnt(0 To 2) As Double
 insertionPnt(0) = 0
 insertionPnt(1) = 0
 insertionPnt(2) = 0
 Set blockObj = ThisDrawing.Blocks.Add _
 (insertionPnt, "CircleBlock")
 ' Add a circle to the block
 Dim circleObj As AcadCircle
 Dim center(0 To 2) As Double
 Dim radius As Double
 center(0) = 0
 center(1) = 0
 center(2) = 0
 radius = 1
 Set circleObj = blockObj.AddCircle(center, radius)
 ' Insert the block
 Dim blockRefObj As AcadBlockReference
 insertionPnt(0) = 2
 insertionPnt(1) = 2
 insertionPnt(2) = 0
 Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock _
 (insertionPnt, "CircleBlock", 1#, 1#, 1#, 0)
 MsgBox "The circle belongs to " & blockRefObj.ObjectName
 ' Explode the block reference
 Dim explodedObjects As Variant
 explodedObjects = blockRefObj.Explode
 ' Loop through the exploded objects
 Dim I As Integer
 For I = 0 To UBound(explodedObjects)
 explodedObjects(I).Color = acRed
 MsgBox "Exploded Object " & I & ": " _
 & explodedObjects(I).ObjectName
 explodedObjects(I).Color = acByLayer
End Sub