Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

ACAD-VBA Change DynamicBlockSize?

Status
Not open for further replies.

mfleming

Structural
Oct 24, 2004
64
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

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

Suggestions?
 
Replies continue below

Recommended for you

Hi mfleming,

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?
 
Hi mfleming,

Jason Booth posted this over at Autodesk, this may or may not be your issue though:
Very often in VBA, variant data types can not be accessed properly via late binding. You must get/set the values before trying to interact with them.

For example:

dim atts as variant
set atts = blockref.GetDynamicBlockProperties()
'atts will now be an array of dynamic block attributes and can now be read/modified.

HTH
Todd
 
TCARPENTER1

I believe I already use the GetDyn.... code except when I try to put the () at the end I get an error.

Code:
lookuptbl = elementBlock.GetDynamicBlockProperties

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:
Set lookuptbl(4).Show = False


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??
 
 http://flemingds.com/uploads/DYN-Foam.gif
Hi mfleming,

Looks like you're almost there, try changing this line:
Code:
lookuptbl = elementBlock.GetDynamicBlockProperties
to:
Code:
[b][purple]Set[/purple][/b] lookuptbl = elementBlock.GetDynamicBlockProperties
and this line:
Code:
Set lookuptbl(4).Show = False
to:
Code:
lookuptbl(4).Show = False
You shouldn't need the 'Set' on the second line of code, that's what's giving the error.

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
 
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?

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
 
Nope chaninging
Code:
lookuptbl = element.GetDynamicBlockProperties
TO
Code:
Set lookuptbl = element.GetDynamicBlockProperties
gives me Run-Time error 13.. Type mismatch. It works ok if I leave OFF the Set.

My New Code:
Code:
Private Sub CommandButton4_Click()
    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

I get this error Run-time error '450' - Wrong number of arguments or invalid property assignment for
Code:
lookuptbl(4).Show = False

What am I missing?
 
Hmm... not sure, give this a shot, I'm just thinking off the cuff here, but maybe you need to verify the existence of some of these:
Code:
Private Sub CommandButton4_Click()
  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
 
TCARPENTER1 I get error 13 Type Mismatch in
Code:
Debug.Print "lookuptbl(" & lCnt & "): Show --> " & lookuptbl(lCnt).Show & _
                                 " Property Name --> " & lookuptbl(lCnt).PropertyName & _
                                         " Value --> " & lookuptbl(lCnt).Value
 
Okay, break it down a little further:

Code:
Debug.Print "lookuptbl(" & lCnt "):"
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
 
Error 13 Type Mismatch
Code:
Debug.Print "          Value---> " & lookuptbl(lCnt).Value
 
So from my original question, how do I update/change these values?
 
Hi mfleming,

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
 
I tried Swamp but no reply.

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:
dybprop(i).Value = "12"
Under the watch window the type is Variant/String and for value it just says custom. I'm thinking it needs 3 values. 1st Value is number, 2nd Value in Number and 3rd is String (as this is what is needed if actually adding a Dynamic Block in AutoCAD not using VBA)

This is my code:

BUTTON:
Code:
Private Sub CommandButton8_Click()
    ScanBlksLookups
End Sub

OTHER PART
Code:
Private Sub ScanBlksLookups()
    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

 
Another stupid question I have is how to I run the Program in Autocad? When I load the project it shows the parts where it actually goes throught the drawings/blocks (not sure what this is called) but I cant see the FORM WINDOW unless I use the TEST function inside the VBA Editor.

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?
 
Hi mfleming,

Sorry those guys couldn't help you out...

Here's how I do it:

[ol]
[li]Create a small VBA app:
Code:
Public Sub <<RoutineName>>
  Userform1.Show '<-- <<Formname>>.Show
End Sub
[/li]

[li]Then, just create a short LISP routine to load and run it from the command line:
Code:
(defun C:VV () 
  (command "-vbaload" "C:\\LISP\\DVB\\Airfoil.dvb")
  (command "-vbarun" "Module1.TestRegion")
)
[/li]
[/ol]

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.

HTH
Todd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor