Published on Tuesday, 26 February 2008 18:36
Add a block to the modelspace. First start of by creating a block in AutoCAD and save it using WBLOCK to the C:\ drive (you can name it Block.dwg) . When completed PURGE the drawing (or open a new one) and add the following code to its VBA instance.
Private Sub InsertBlock()
InsertBlock "C:\Block.dwg", 0
'Change the 0 to another value (in degrees) to rotate the block
Function InsertBlock(ByVal blockpath As String, ByVal rotation As Double)
Dim blockobj As AcadBlockReference
Dim insertionPnt As Variant
Dim prompt1 As String
'set rotation Angle
rotateAngle = rotation
rotateAngle = rotation * 3.141592 / 180#
'Prompt is used to show instructions in the command bar
prompt1 = vbCrLf & "Enter block insert point: "
ThisDrawing.ActiveSpace = acModelSpace
insertionPnt = ThisDrawing.Utility.GetPoint(, prompt1)
Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock(insertionPnt, blockpath, 1#, 1#, 1#, rotateAngle)
'Change Modelspace into Paperspace to insert the block into Paperspace
The code will get the block, ask you for its insert point and then places it into the modelspace.
It could be useful to explode a block upon insertion. To do so add the following line after 'Set blockrefobj......'
Download AutoCad Block sample Here