29 | 04 | 2017

Insert Block

{jcomments on}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 InsertBlock1()

'****************************************
'*** Code from VisibleVisual.com ********
'****************************************
InsertBlock "C:\Block.dwg", 0
'Change the 0 to another value (in degrees) to rotate the block'

End Sub

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

End Function

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......'

BlockRefobj.Explode

Download the source code below (Registered users only). 

Login

Sign up now and upload your code to the website.

Help us to continue.....
Statistics
Articles View Hits
2237952
Latest Articles