Change layer inside a block

Change layer inside a block

andreas7ZYXQ
Advocate Advocate
8,310 Views
5 Replies
Message 1 of 6

Change layer inside a block

andreas7ZYXQ
Advocate
Advocate

I have a block and within that ive got a nested one. The nested block is placed on "layer1"

Im looking for a lisp routine that will change the layer. It would something like this:


1. Select a object and extract the layer its placed on, lets say  "lay".
2. Start to select blocks to change.

3. Press enter and change the nested block thats placed on layer1(only obejct on layer1) to lay for all selecterd blocks.

 

Does anyone have something like this or could give me a hand since this is a bit over my knowledge.
Thanks.

 

/ante

0 Likes
Accepted solutions (2)
8,311 Views
5 Replies
Replies (5)
Message 2 of 6

Kent1Cooper
Consultant
Consultant

Your wording "only object on layer1" suggests something:  If, by chance, there are no objects  in the drawing on the "layer1" Layer other than  those nested Blocks, LAYMRG will take care of it for you.  Can it be that simple?

Kent Cooper, AIA
0 Likes
Message 3 of 6

andreas7ZYXQ
Advocate
Advocate
Actually there is plenty of objects on the layer so I think it will not work.

In my workflow I just choose some that have to change since I filthier them when printing.
0 Likes
Message 4 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

@andreas7ZYXQ wrote:
Actually there is plenty of objects on the layer so I think it will not work.
....

How 'bout this?  Very lightly tested, and without the usual enhancements:

(defun C:CNBL (/ esel ss tarlay n blkname blklist done ent edata); = Change Nested Block Layer
  (if
    (and
      (setq esel (entsel "\nObject on target Layer: "))
      (not (prompt "\nBlocks in which to change nested Block on Layer1 to target Layer: "))
      (setq ss (ssget '((0 . "INSERT"))))
    ); and
    (progn ; then
      (setq tarlay (cdr (assoc 8 (entget (car esel)))))
      (repeat (setq n (sslength ss))
        (if (not (member (setq blkname (cdr (assoc 2 (entget (ssname ss (setq n (1- n))))))) blklist))
; only one Block name if more than one of same name selected (setq blklist (cons blkname blklist)) ); if ); repeat (foreach blkname blklist (setq done nil ; reset for each ent (tblobjname "block" blkname); the Block definition ); setq (while (and (not done) (setq ent (entnext ent))); step through pieces (if (= (strcase (cdr (assoc 8 (setq edata (entget ent))))) "LAYER1");; <-- EDIT for actual Layer name (progn ; then (entmod (subst (cons 8 tarlay) (assoc 8 edata) edata)); change its Layer (setq done T); stop looking through this Block ); progn ); if ); while ); foreach (command "_.regen"); to change visibly ); progn ); if (princ) ); defun

 

That counts on your statement that the nested Block is the only  thing on that Layer in the host Block, so it doesn't check for whether an object it finds on that Layer is, in fact, a Block [but it could if needed], and it stops looking as soon as it finds anything on that Layer among the Block's parts.

Kent Cooper, AIA
0 Likes
Message 5 of 6

andreas7ZYXQ
Advocate
Advocate

Fabulous @Kent1Cooper

 

I have a question.

It works just as i want exept for a small detail.
If i have 10 blocks with the same name it will change all ten even if i just select one of them.

 

Correct me if im wrong. Im trying to learn, but is it possible to get the  (-1 . <Entity name: 1aa711490e0>) for each selected block and just apply the change to them?

Im so grateful for your help!

0 Likes
Message 6 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

@andreas7ZYXQ wrote:

....
It works just as i want exept for a small detail.
If i have 10 blocks with the same name it will change all ten even if i just select one of them.

 

Correct me if im wrong. Im trying to learn, but is it possible to get the  (-1 . <Entity name: 1aa711490e0>) for each selected block and just apply the change to them?
....


You can't do it that way with ordinary Blocks.  It's the nature of changing something in a Block definition -- every Block of the same name gets the same change.  That's why the routine makes a list of Block names, checking for each selected Block whether its name is already in the list, because there's no point in changing the definition of a Block more than once.

 

Otherwise, the benefit to a Block definition is gone -- the memory savings from the collective definition and the fact that their ingredients are all the same [they vary only as to their insertion points/scales/rotations, with further dimensional variabilities in Dynamic Blocks (but see below) and/or textual variabilities via Attributes].  To have them be different in the way you describe would, I think, mean Exploding  all those Blocks and changing the Layer of the Block that was formerly nested in them all.  Or, you could pull the nested Block out of the parent Block's definition and Insert one on the Layer you want at the Insertion point of each of the other Blocks.  But that would also remove them from the Blocks you don't want to change, so you'd have to add the formerly-nested Block at each of those, too, on some Layer or other.

 

You could also do what you're asking by changing the Layer of the nested Block to Layer 0  in the Block definition, rather than to your target Layer, and then changing the Layer of the parent Block  to the target Layer [because of the characteristics of Layer 0 in relationship to Block definitions].  Would that work?  It would depend on there not  being other things drawn on Layer 0 in the parent Block's definition.

 

[I'm not fully up to speed on Dynamic Blocks -- if there's a way for their Dynamism to include the Layers  of objects in them, including nested Blocks, it may be possible, but others will need to help with that, unless and until I dig into them.]

Kent Cooper, AIA
0 Likes