Select all blocks using selection sets

Select all blocks using selection sets

Anonymous
Not applicable
3,972 Views
9 Replies
Message 1 of 10

Select all blocks using selection sets

Anonymous
Not applicable

I'm trying to select all blocks on all layers using selection sets. My code is something like this:

 

ThisDrawing.SelectionSets.Item("VBA").Delete
Set selecao_blocos = ThisDrawing.SelectionSets.Add("VBA")
gpcode(0) = 8: datavalue(0) = "*"

gpcode(1)=????: datavalue(1)=???
selecao_blocos.Select acSelectionSetAll, , , gpcode, datavalue

 

As you can see I'm already selecting all layers. Now what do I have to put on gpcode a datavalue to select all blocks on the drawing?

 

 

0 Likes
Accepted solutions (1)
3,973 Views
9 Replies
Replies (9)
Message 2 of 10

cadffm
Consultant
Consultant
Accepted solution

https://www.autodesk.com/techpubs/autocad/acadr14/dxf/group_codes_in_numerical_order_al_u05_c.htm

 

gc 1 you dont need

 

gc 0 => "INSERT"

 

But external references (XRefs) are displayd by inserts too, you have to remove this item if you dont want XRef -Blockreferences.

(it is not possible directly in the filterlist - or i dont know how. With Lisp it isn't)

 

 

 

 

Sebastian

Message 3 of 10

Ed__Jobe
Mentor
Mentor

Also, if you are selecting all layers then you don't need to filter that either.

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

0 Likes
Message 4 of 10

Anonymous
Not applicable

Imagine that I want to select all blocks named "TEST_BLOCK1" and "BLOCK_NAME1". Is there a way to create a selection set for this situation?

0 Likes
Message 5 of 10

cadffm
Consultant
Consultant
Look for DXF Reference (for example my link) and your Help [F1]

The Blockname is stored in Inserts with DXF Groupcode 2
as Value you can combine multiple names and wildcards.
"BlockTest,Testblock,MyTestblock" (it is not case sensitive)

Note: That isn't working well for dynamic blocks

(Hint for later with other Blocknames: Think about special characters in Blocknames)

Sebastian

Message 6 of 10

Anonymous
Not applicable

Thank you for the tip, I didn't know I could specify multiple names. All my blocks are dynamic and it is working well for now. Is there a workaround for dynamic blocks with which it doesn't work well?

 

 

0 Likes
Message 7 of 10

cadffm
Consultant
Consultant
"All my blocks are dynamic and it is working well for now"

Is it working well, or NOT?

Please test it with dynamic block inserts after you edit them by dynamic properties like strech, move..

A workaround is
Catch ALL inserts and check every item of them for the effectivename (propertie), remove if not match your Blockname..

Sebastian

Message 8 of 10

Anonymous
Not applicable

Yes, it is working. I just asked in case I receive a drawing that contains blocks where this doesn't work. Thanks for your help 🙂

0 Likes
Message 9 of 10

norman.yuan
Mentor
Mentor

With block name as SelectionSet's selecting filter for dynamic block would be problematic, to say the least, as @cadffm pointed out.

 

In your case, when you say it works, its reason is ONLY because the dynamic block reference's dynamic property or properties is/are not set to a value so that AutoCAD has to dynamically generate an anonymous block definition for this dynamic block reference. In most, if not all, times when a dynamic propery changes, AutoCAD generates an anonymous block definition for the dynamic block reference. That means, a dynamic block reference may, or very likely, have a different name (like *xxxx") from its original dynamic block definition's name. Thus, filtering by name on dynamic block references would fail to select the block references in interest.

 

Depending on what kind of dynamic properies your dynamic block has, you can try to set the properties to different values and run your "working" code. I gurantee you would find some targeted blcok references are not selected.

 

So, as @cadffm said, if your target block references are dynamic blocks, you'd better only set filter to Entity name ("INSERT" in your case, but not apply block name filter).

 

After the selection set gets all the block refernces, you can loop through the selection setand test each selected block referbce by its "EffectiveName" to identify the target block references.

 

Norman Yuan

Drive CAD With Code

EESignature

Message 10 of 10

Anonymous
Not applicable

Thank you for the explanation. It was very helpful

0 Likes