ACAD-VBA Change DynamicBlockSize?
ACAD-VBA Change DynamicBlockSize?
(OP)
Hello.
I'm working on an app that will take width & height values from an excel file and add them to the LOOKUP of my rectangle shape Dynamic Block.
In the end I want to be able to update my Dynamic Blocks in the drawing with the NEW LOOKUP values to Stretch the Width & Height.
My Dynamic Block:
PropertyName = "LabelHeight" & "LabelWidth"
Block Name = "DYN-Foam"
I can get the PropertyName and Value using "GetDynamicBlockProperties" and the ".PropertyName" & ".Value" but I cant seem to erase all of them and put in new ones.
STEP 1 - In the Dynamic Block Updating
Suggestions?
I'm working on an app that will take width & height values from an excel file and add them to the LOOKUP of my rectangle shape Dynamic Block.
In the end I want to be able to update my Dynamic Blocks in the drawing with the NEW LOOKUP values to Stretch the Width & Height.
My Dynamic Block:
PropertyName = "LabelHeight" & "LabelWidth"
Block Name = "DYN-Foam"
I can get the PropertyName and Value using "GetDynamicBlockProperties" and the ".PropertyName" & ".Value" but I cant seem to erase all of them and put in new ones.
STEP 1 - In the Dynamic Block Updating
CODE
Private Sub CommandButton4_Click()
Dim element As Object
Dim elementBlock As AcadBlockReference
Dim ArrayAttributes As Variant
Dim i As Integer
Dim pname As Variant
Dim lookuptbl As Variant
Dim width As Double
Dim height As Double
For Each elementBlock In ThisDrawing.ModelSpace
If elementBlock.IsDynamicBlock = True Then
lookuptbl = elementBlock.GetDynamicBlockProperties
'The stuff below is for reference only
ListBox1.AddItem pname
ListBox2.AddItem lookuptbl(4).PropertyName
ListBox2.AddItem lookuptbl(4).Value
'ListBox2 = lookuptbl(4).AllowedValues(1)
'I cant seem to get the AllowedValues but I can see them in the watch window.
ListBox2.AddItem " "
ListBox2.AddItem lookuptbl(5).PropertyName
ListBox2.AddItem lookuptbl(5).Value
ListBox2.AddItem " "
ListBox2.AddItem lookuptbl(0).PropertyName
ListBox2.AddItem lookuptbl(0).Value
End If
Next
End Sub
Dim element As Object
Dim elementBlock As AcadBlockReference
Dim ArrayAttributes As Variant
Dim i As Integer
Dim pname As Variant
Dim lookuptbl As Variant
Dim width As Double
Dim height As Double
For Each elementBlock In ThisDrawing.ModelSpace
If elementBlock.IsDynamicBlock = True Then
lookuptbl = elementBlock.GetDynamicBlockProperties
'The stuff below is for reference only
ListBox1.AddItem pname
ListBox2.AddItem lookuptbl(4).PropertyName
ListBox2.AddItem lookuptbl(4).Value
'ListBox2 = lookuptbl(4).AllowedValues(1)
'I cant seem to get the AllowedValues but I can see them in the watch window.
ListBox2.AddItem " "
ListBox2.AddItem lookuptbl(5).PropertyName
ListBox2.AddItem lookuptbl(5).Value
ListBox2.AddItem " "
ListBox2.AddItem lookuptbl(0).PropertyName
ListBox2.AddItem lookuptbl(0).Value
End If
Next
End Sub
Suggestions?





RE: ACAD-VBA Change DynamicBlockSize?
I haven't played with dynamic blocks much, or the code associated with them, but, I see you are listing the values but I don't how you have tried clearing or setting them. What happens when you try and set/clear these values? Are you generating an error, or is just that nothing happens?
Or is this more a form problem?
RE: ACAD-VBA Change DynamicBlockSize?
Jason Booth posted this over at Autodesk, this may or may not be your issue though:
HTH
Todd
RE: ACAD-VBA Change DynamicBlockSize?
I believe I already use the GetDyn.... code except when I try to put the () at the end I get an error.
CODE
lookuptbl GETS the info and it displays it as lookuptbl(0), lookuptbl(1) and so on.
I tried changing the "show" value and I get an error. This is where I don't now how to change any values. (see attachment) This code below should work right?
CODE
Also I cant find my values I used for my Lookup parameter inside AutoCAD under the lookuptbl(0) thru (5). It only shows my Description of the Lookups under the AllowableValues. ie. Foam 24"x48" or Foam 36"x64" ect. It doesn't show the 24" or 48" which are the actual values that change the size of the Block.
I guess I'm not working with the array properly or something??
RE: ACAD-VBA Change DynamicBlockSize?
Looks like you're almost there, try changing this line:
CODE
CODE
CODE
CODE
If I understand the AllowableValues part, that's for a predefined range, so your values may or may not be there? If you look in the watch window, you do have a PropertyName with a value of "Label/Width" and it's value is set to 24. Wasn't that the parameter for changing your width and height?
HTH
Todd
RE: ACAD-VBA Change DynamicBlockSize?
Yes and No. This will change the width and height using their parameters BUT I want to add them the LookUP Paramater (which basically has a big list of widths and lengths in specific combinations (ie. 24"w X 48"h, 24"w X 32"h, 22"w X 48"h)
I'm wanting to use my excel list to be updated into the LookUP Parameter in AutoCAD. The AutoCAD LookUP parameter is in my Watch window as lookuptbl(4).AllowabelValues.
I will change those other values you mentioned and see if that helps.
Thanks
RE: ACAD-VBA Change DynamicBlockSize?
CODE
CODE
My New Code:
CODE
Dim element As Object
Dim lookuptbl As Variant
For Each element In ThisDrawing.ModelSpace
If element.IsDynamicBlock = True Then
lookuptbl = element.GetDynamicBlockProperties
lookuptbl(4).Show = False
'The stuff below is for reference only and Displays Fine
ListBox1.AddItem pname
ListBox2.AddItem lookuptbl(4).PropertyName
ListBox2.AddItem lookuptbl(4).Value
End If
Next
End Sub
CODE
RE: ACAD-VBA Change DynamicBlockSize?
CODE
Dim element As Object
Dim lookuptbl As Variant
Dim lCnt as Long
For Each element In ThisDrawing.ModelSpace
If element.IsDynamicBlock = True Then
lookuptbl = element.GetDynamicBlockProperties
For lCnt = LBound(lookuptbl) to UBound(lookuptbl)
Debug.Print "lookuptbl(" & lCnt & "): Show --> " & lookuptbl(lCnt).Show & _
" Property Name --> " & lookuptbl(lCnt).PropertyName & _
" Value --> " & lookuptbl(lCnt).Value
Next lCnt
End If
Next element
End Sub
See if that produces the results it should, or if you find some other issues.
HTH
Todd
RE: ACAD-VBA Change DynamicBlockSize?
CODE
" Property Name --> " & lookuptbl(lCnt).PropertyName & _
" Value --> " & lookuptbl(lCnt).Value
RE: ACAD-VBA Change DynamicBlockSize?
CODE
Debug.Print " Show --> " & lookuptbl(lCnt).Show
Debug.Print " Property Name --> " & lookuptbl(lCnt).PropertyName
Debug.Print " Value---> " & lookuptbl(lCnt).Value
This way you'll at least know which one you're bombing out on, and then you can fix your code from there.
HTH
Todd
RE: ACAD-VBA Change DynamicBlockSize?
CODE
RE: ACAD-VBA Change DynamicBlockSize?
RE: ACAD-VBA Change DynamicBlockSize?
I'm sorry, I've hit a wall with this one, and there doesn't seem to be too many people over at Autodesk's forum that know too much about this either. There were a few posts similiar to yours - the one I quoted above, but that's about it. You might try posting this one over at Autodesk's AutoCAD customization forum and see if anyone knows. You might also try the guys over at the Swamp, a lot of those guys are heavy hitters when it comes to AutoCAD programming.
Good Luck
Todd
RE: ACAD-VBA Change DynamicBlockSize?
I have got it so I can change the visibily state. Just not sure what "values" I use to set the lookup. I keep getting Invalid input.
CODE
This is my code:
BUTTON:
CODE
ScanBlksLookups
End Sub
CODE
Dim dybprop As Variant, i As Integer
Dim bobj As AcadEntity
For Each bobj In ThisDrawing.ModelSpace 'Get AutoCAD Entity's
Debug.Print bobj.ObjectName
If bobj.ObjectName = "AcDbBlockReference" Then 'Check if BlockRef
If bobj.IsDynamicBlock Then 'Check to see if it is a Dynamic Block
dybprop = bobj.GetDynamicBlockProperties
If bobj.EffectiveName = "DYN-Foam" Then 'Finds Dynamic Block NAME
For i = LBound(dybprop) To UBound(dybprop) 'Goes through Results
If dybprop(i).PropertyName = "Lookup" Then 'Looks for the PropertyName
dybprop(i).Value = "12" 'Change the Value of the PropertyName
End If
Next i
End If
End If
End If
RE: ACAD-VBA Change DynamicBlockSize?
Basically what do I enter in AutoCAD for the Form to show up so I can click the button for it to do its thing with the blocks?
RE: ACAD-VBA Change DynamicBlockSize?
Sorry those guys couldn't help you out...
Here's how I do it:
- Create a small VBA app:
Public Sub <<RoutineName>> - Then, just create a short LISP routine to load and run it from the command line:
(defun C:VV ()
If you want it available all the time for your users, you can place the lisp routine in the ACAD.LSP file, or use the appload command, and place it in the startup suite of files.CODE
Userform1.Show '<-- <<Formname>>.Show
End Sub
CODE
(command "-vbaload" "C:\\LISP\\DVB\\Airfoil.dvb")
(command "-vbarun" "Module1.TestRegion")
)
HTH
Todd