Change attribute value in dynamic block

Change attribute value in dynamic block

stefanveurink68AXD
Advocate Advocate
1,805 Views
3 Replies
Message 1 of 4

Change attribute value in dynamic block

stefanveurink68AXD
Advocate
Advocate

So, I've got some code to look for a block and change a certain attributevalue. 

 

This code works fine for as long as its just a block

 

At dynamic blocks however (the block I want to change the value of does also have an visibility state in it. The attribute value isn't connected to the visibility state and the same in all states) it doesn't work anymore.

 

Anyone knows how to deal with it?

 

The code i've got looks something like this: 

For Each obj In ThisDrawing.PaperSpace
        If TypeOf obj Is AcadBlockReference Then
            If obj.Name = "Iv-Tekhoofd_A0_V2.8" Then
                attlist = obj.GetAttributes
                For i = LBound(attlist) To UBound(attlist)
                    If attlist(i).TagString = "SHEET_NO" Then
                        attlist(i).TextString = layout.TabOrder & " van " & aantal
                    End If
                Next
            End If
        End If
        Next
0 Likes
Accepted solutions (2)
1,806 Views
3 Replies
Replies (3)
Message 2 of 4

norman.yuan
Mentor
Mentor
Accepted solution

If you had done debugging by stepping through the code line by line, you would have noticed that the code execution did not go inside "If obj.Name="...." Then" because the dynamic block reference's name is likely an anonymous block definition's name. You should use "EffectiveName" instead of "Name":

 

Dim blk As AcadBlockReference
For Each obj In ThisDrawing.PaperSpace If TypeOf obj Is AcadBlockReference Then
Set blk = obj If UCase(blk.EffectiveName) = UCase("Iv-Tekhoofd_A0_V2.8") Then attlist = obj.GetAttributes For i = LBound(attlist) To UBound(attlist) If attlist(i).TagString = "SHEET_NO" Then attlist(i).TextString = layout.TabOrder & " van " & aantal End If Next End If End If Next

HTH

 

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 4

stefanveurink68AXD
Advocate
Advocate

Thanks, it works so you must be right. 

 

But to be honest i seriously don't understand whats the difference. Why with just a block you can use the .name, while with a dynamic block you have to use the .effectivename. Is this generally allways the case? Or is the problem somewhere else? Or what is even the difference? And why the Ucase-setting, is this just an improvement to make sure the wrong use of uppercase doesn't lead to trouble or is there a different reason for using it? It would be very welcome if this would be clear to me so if anyone can clarify this, thanks. 

0 Likes
Message 4 of 4

Ed__Jobe
Mentor
Mentor
Accepted solution

Since dynamic blocks can change, you would have to redefine the original block, each time a parameter changed. That wouldn't work. So what is done is each time a change is required, an anonymous block is created. Anonymous block names begin with *U####. Therefore you can't identify it by its Name property. So when dynamic blocks were introduced, the EffectiveName property was added. It retains the original block name.

 

You may not be familiar with anonymous blocks because they don't show up in the INSERT dialog or the RENAME dialog. Dimensions actually use anonymous blocks.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature