Jump to content

How to access entities inside of an instance of a block


newbie32

Recommended Posts

I've looked everywhere and couldn't find a solution.

All entities inside of that block is on layer "0".

I want to select a block and change all entities inside of that "block instance" to color 2.

 

Thank you.

Link to comment
Share on other sites

Since you are in the lisp forum, I presume you want to know how to do this with lisp code?

 

The code here works as you desire, I just tested it. (You'll just have to modify it to modify the color instead of layer)

 

http://lee-mac.com/applytoblockobjects.html

 

EDIT: Oh wait, you want to only modify a single INSERT of that block definition?!?

Edited by rkmcswain
edit
Link to comment
Share on other sites

The ACAD document has a collection of "Block Definitions" (these are non-graphical objects),

each block definition can be inserted multiple times so every time a "Block Reference" (graphical object) is created.

You cannot manipulate the geometry properties of a single block reference (except the position/rotation/scale factor and the attributes/parameters).

 

Untested:

(defun C:test ( / doc )
 (if 
   (not 
     (vl-catch-all-error-p
       (vl-catch-all-apply
         (function
           (lambda nil
             (vlax-for o 
               (vla-Item
                 (vla-get-Blocks (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))))
                 (vla-get-EffectiveName (vlax-ename->vla-object (car (entsel "\nSelect block: "))))
               )
               (vl-catch-all-apply
                 (function 
                   (lambda nil
                     (vla-put-Layer o "0")
                     (vla-put-Color o 2)
                   )
                 )
               )
             )
           )
         )
       )
     )
   )
   (vla-Regen doc acAllViewports)
 )
 (princ)
)

Link to comment
Share on other sites

I've looked everywhere and couldn't find a solution.

All entities inside of that block is on layer "0".

I want to select a block and change all entities inside of that "block instance" to color 2.

 

If you really wish to modify a single reference of a block, then you will first need to copy the block definition (so as not to affect other references of the block in the drawing) and then modify the components of the copied definition, which is now only referenced by the single block reference that you selected.

Link to comment
Share on other sites

Nice one Grrr! For fun's sake, let's say you have/select a dynamically modified insertion (named *u123) of a block def (named A), your code goes in the block table and modify the block definition corresponding to the effective name of the insertion you chose, which means that it will modify the original block definition, update the inserts of all the *not* dynamically modified insertion and actually leave untouched the block of the insert the user actually did choose. It can be fixed by changing (vla-get-EffectiveName to (vla-get-Name.

 

There is something artistic about the way you code. Always fun to see how you achieve things. :)

 

:beer:

Link to comment
Share on other sites

Nice one Grrr! For fun's sake, let's say you have/select a dynamically modified insertion (named *u123) of a block def (named A), your code goes in the block table and modify the block definition corresponding to the effective name of the insertion you chose, which means that it will modify the original block definition, update the inserts of all the *not* dynamically modified insertion and actually leave untouched the block of the insert the user actually did choose. It can be fixed by changing (vla-get-EffectiveName to (vla-get-Name.

 

Without a sample drawing I'm too lazy to test.

But yeah, I didn't thought about an annonymously generated block definition..

I always stick on modifying the base block def, so perhaps the Update or ResetBlock method might be handy to update the annonymous one (just a guess).

However I'm not sure if OP exactly wants the behavour of the program suggested by you (wait for his answer).

 

There is something artistic about the way you code. Always fun to see how you achieve things. :)

 

:beer:

 

Thanks, I'm just having fun! :beer:

Link to comment
Share on other sites

But yeah, I didn't thought about an annonymously generated block definition..

.

While modified dynamic blocks are anonymous *u blocks, not all anonymous *u blocks are modified dynamic blocks. Perhaps you used get-effective-name just by habit, but since get-effective-name's sole purpose is to go from an insert of a modified dynamic blocks to the name of its "parent", the original block's definition I would be tempted to say that you had some subconscious thoughts about them. :D

I always stick on modifying the base block def

Not quite. Usually you get the effective-name, change corresponding block, then ssget all insert named *u and iterate through them and keep all the one that have the same effective name then modify their reference. I cannot think of any reason why you would want to, after selection a "child" (a dynamically modified insert of a block), not change the "child"'s definition but go and modify solely the "parent"'s block definition. Basically, you never stick on (only) modifying the base block def (which you did here). Depending on what you want to achieve, you either modify only the selected *u block or both the base block definition and all the *u block derived from it.

 

perhaps the Update or ResetBlock method might be handy to update the annonymous one (just a guess).
The update method graphically redraw something. Think of it as a "entity level localized regen". As for the reset block would have a catastrophic outcome as it would revert all modified inserts to their original state (unstretched, unrotated, original dysplay state, etc) and the user would loose potentially hours of work. I would say that if he wanted the blocks to all be reset to their original geometry, chances are he would not have made/used dynamic blocks in the first place.

 

Thanks, I'm just having fun!
It shows. I can only hope I'm not ruining it too much! :)
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...