26 | 04 | 2017

Insert Dynamic Block and set variables

In previous examples we show how to insert a block into modelspace. However much more can be obtained using dynamic blocks. For example you can create a table with variable width and length. All dynamic block futures can be called from VBA. Below a example of how to insert a block with to Custom variables called Xvalue and Yvalue representing the width and length of the object. Scroll down to download the sample files.

 

Sub PlaceDynamicBlock()
'****************************************
'*** Code from VisibleVisual.com ********
'****************************************

Dim blockobj As AcadBlockReference
Dim pnt As Variant

'Prompt is used to show instructions in the command bar
prompt1 = vbCrLf & "Enter block insert point: "

ThisDrawing.ActiveSpace = acModelSpace

pnt = ThisDrawing.Utility.GetPoint(, prompt1)
Set blockobj = ThisDrawing.ModelSpace.InsertBlock(pnt, "C:\SampleBlock.dwg", 1#, 1#, 1#, 0)

 Variable = blockobj.GetDynamicBlockProperties

For I = LBound(Variable) To UBound(Variable)

'Check for variable and when found ask for input
If Variable(I).PropertyName = "Xvalue" Then
Variable(I).Value = CDbl(InputBox("Enter Width in mm!", "Enter Value", 200))
End If

If Variable(I).PropertyName = "Yvalue" Then
Variable(I).Value = CDbl(InputBox("Enter Height in mm!", "Enter Value", 200))
End If

Next I

blockobj.Update

End Sub
 
As you can imagine this create a whole new range of possibilities to the block object. With one block you can create a whole diversity of drawings.

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
2234973
Latest Articles