Home AutoCad VB Insert Dynamic Block and set variables
20 | 05 | 2012
This site has been updated and renewed. You have followed an old link.

Click here to go to the new site

http://www.visiblevisual.com/jupgrade

Insert Dynamic Block and set variables PDF Print E-mail
User Rating: / 3
PoorBest 
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.

Show/Hidden vbnet code

View source
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.

 

 


Attachments:
FileDescriptionFile sizeDownloads
Download this file (Dynamic.zip)Insert Dynamic BlockInsert Dynamic Block and set Variables3 Kb649
 

Comments   

 
0 #3 Guest 2011-02-21 21:54
Yikes, my < and > got eaten by the editor.
Choose "Current Drawing" from the list.
Quote
 
 
0 #2 Guest 2011-02-21 21:52
To answer myself:
When opening the block editor, do NOT give the block a name!
Instead, choose "" from the list.
Quote
 
 
0 #1 Guest 2011-02-20 20:19
That looks like just what I need.
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?
Quote
 

Add comment


Security code
Refresh

This site has been updated and renewed. You have followed an old link.

Click here to go to the new site

http://www.visiblevisual.com/jupgrade