| Insert Dynamic Block and set variables |
|
|
|
| Tutorials | |||
|
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.
|





Comments
Choose "Current Drawing" from the list.
When opening the block editor, do NOT give the block a name!
Instead, choose "" from the list.
Unfortunately, I have a hard time saving the dynamic block. Specifically, I cannot save an instance of the dynamic block that I can load like you show above.
Any hints to that?
RSS feed for comments to this post