Insert Blocks

AutoCAD ActiveX

 
Insert Blocks
 
 
 

You can insert blocks or entire drawings into the current drawing with the InsertBlock method. The InsertBlock method takes six values as input: the insertion point, the name of the block or drawing to insert, the X-scale factor, the Y-scale factor, the Z-scale factor, and the rotation angle.

When you insert an entire drawing into another drawing, AutoCAD treats the inserted drawing like any other block reference. Subsequent insertions reference the block definition (which contains the geometric description of the block) with different position, scale, and rotation settings. If you change the original drawing after inserting it, the changes have no effect on the inserted block. If you want the inserted block to reflect the changes you made to the original drawing, you can redefine the block by reinserting the original drawing. This can be done with the InsertBlock method.

If you insert a drawing as a block, the file name is automatically used as the name of the block. You can change the name of the block by using the Name property once the block has been created.

By default, AutoCAD uses the coordinate (0, 0, 0) as the base point for inserted drawings. You can change the base point of a drawing by opening the original drawing and using the SetVariable method to specify a different insertion base point for the INSBASE system variable. AutoCAD uses the new base point the next time you insert the drawing.

If the drawing you insert contains PaperSpace objects, those objects are not included in the current drawing's block definition. To use the PaperSpace objects in another drawing, open the original drawing and use the Add method to define the PaperSpace objects as a block. You can insert the drawing into another drawing in either paper space or model space.

A block reference cannot be iterated to find the original objects that compose it. However, you can iterate the original block definition, or you can explode the block reference into its original components.

You can also insert an array of blocks using the AddMInsertBlock method. This method does not insert a single block into your drawing, as the InsertBlock does, but instead inserts an array of the specified block. This method returns an MInsertBlock object.

For more information on inserting blocks, see “Insert Blocks” in the User's Guide.

Define a block and insert the block into a drawing

This example defines a block and adds a circle to the block definition. It then inserts the block into the drawing as a block reference.

Sub Ch10_InsertingABlock()
 ' 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)
 ZoomAll
 MsgBox "The circle belongs to " & blockRefObj.ObjectName
End Sub
NoteAfter insertion, the external file's WCS is aligned parallel to the XY plane of the current user coordinate system (UCS) in the current drawing. Thus, a block from an external file is inserted at any orientation in space by setting the UCS before inserting it.