Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Changing a Block from One Layer to a Different Layer

11 REPLIES 11
Reply
Message 1 of 12
Anonymous
697 Views, 11 Replies

Changing a Block from One Layer to a Different Layer

Hello,

 

I have been trying different thing and cant figure it out and need some help.

 

We have made several revisions to plans and have several deltas and bubbles on the sheets and the bubbles and deltas are the same layer (I.E. for Revision 1 the bubbles and deltas are RV1 layer, Revision 2 the bubbles and deltas are RV2 layer).

 

Is there a way to find each block (delta) with a certain layer and change the layer to a new layer without affecting the bubble's layer. Also is it able to not get hung up if there is an RV2 and RV4 but no RV1 or RV3?

 

Basically we need to change the delta or bubble (whichever is easier) to its own layer, like RV1DELTA (or something in that area).

 

We have a bunch of sheets like this is why I am looking for a lisp routine or something that can help so I dont have to go into each sheet and create a new layer one by one for each revision layer. The Deltas are blocks and the bubbles are not, if that helps. (BLOCK NAME: TRINOTE, BLOCK TAG: ?TRINOTE)

 

I am also hoping I can batch this for all of the drawings inside the folder so I dont have to open every single one but trying to get the initial layer change down first.

 

Please let me know if you need more information.

 

Thanks!

11 REPLIES 11
Message 2 of 12
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

... 

We have made several revisions to plans and have several deltas and bubbles on the sheets and the bubbles and deltas are the same layer (I.E. for Revision 1 the bubbles and deltas are RV1 layer, Revision 2 the bubbles and deltas are RV2 layer).

 

Is there a way to find each block (delta) with a certain layer and change the layer to a new layer without affecting the bubble's layer. Also is it able to not get hung up if there is an RV2 and RV4 but no RV1 or RV3?

 

Basically we need to change the delta or bubble (whichever is easier) to its own layer, like RV1DELTA (or something in that area).

 

.... (BLOCK NAME: TRINOTE, BLOCK TAG: ?TRINOTE)

....


Something like this is one way [untested]:

 

(if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "TRINOTE")))); find any such Blocks

  (repeat (setq inc (sslength ss))

    (setq

      blk (ssname ss (setq inc (1- inc)))

      lay (strcat (cdr (assoc 8 (entget blk))) "DELTA"); new Layer name

    ); setq

    (command

      "_.layer" "_make" lay "" ; will make if it doesn't exist, & set current either way; won't care if it already exists

      "_.chprop" blk "" "_layer" lay "" ; put that Block on that Layer

    ); command

  ); repeat

); if

Kent Cooper, AIA
Message 3 of 12
Anonymous
in reply to: Kent1Cooper

Awesome! This worked.

 

Now I am writing in to freeze the bubble only and its freezing the delta too because of the names... just need it to ignore the deltas.

 

Edit: Got it to work woith only freezing the bubbles.

Message 4 of 12
Anonymous
in reply to: Anonymous

Looks like it hangs up when there are bubbles in both model and paper space.. If you run it in model space it will work for all in model space but it will not work if you do this in paper space. Any suggestions?

 

Error: The object is not in current space.

Message 5 of 12
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

Looks like it hangs up when there are bubbles in both model and paper space.. If you run it in model space it will work for all in model space but it will not work if you do this in paper space. Any suggestions?

 

Error: The object is not in current space.


Editing commands like CHPROP, in (command) functions, can only "find" things that are in the current space.  If there might be some in other spaces, and you also want those moved to the other Layer, then you would need to either change to their space to CHPROP them, or use (subst)/(entmod) or (vla-put-Layer...) instead of CHPROP to change their Layer.  I can work that out tomorrow if you don't figure it out yourself first.

Kent Cooper, AIA
Message 6 of 12
Anonymous
in reply to: Anonymous

I thought I could get the entmod by trial and error (never tried it before) but cant. Sorry.

 

Also, If the *Delta layer is already created is there a way to ignore creating the layer again (since itll be called *DeltaDelta and just set the "blk" to the already created layer? There will be occasions where we have already ran this command and need to do it again.

 

Thanks for the help. I will read more into the entmod and see if I can learn it better.

Message 7 of 12
Anonymous
in reply to: Anonymous

As for the not looking for the already made block on the "*Delta" layer, can I put (not (8. "DELTA") in the ssget sequence?

 

Just trying to learn while I go..

 

Thanks!

Message 8 of 12
pbejse
in reply to: Anonymous


@Anonymous wrote:

As for the not looking for the already made block on the "*Delta" layer, can I put (not (8. "DELTA") in the ssget sequence?

 

Just trying to learn while I go..

 

Thanks!


YES

 

(setq ss (ssget "_X" '((0 . "INSERT") (2 . "TRINOTE")(-4 . "<NOT") (8 . "*DELTA") (-4 . "NOT>"))))

Message 9 of 12
Anonymous
in reply to: pbejse

  • Ah! I read some more and do see that now.. Thanks!! Now I just gotta figure out the whole subst and entmod.
Message 10 of 12
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:
  • Ah! I read some more and do see that now.. Thanks!! Now I just gotta figure out the whole subst and entmod.

It's just a matter of replacing the Layer entry (assoc 😎 in the entity data with one using the new Layer name.  Something like this ought to do it [again, untested]:

 

(if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "TRINOTE") (-4 . "<NOT") (8 . "*DELTA") (-4 . "NOT>")))); find any such Blocks
  (repeat (setq inc (sslength ss))
    (setq
      blk (ssname ss (setq inc (1- inc)))
      blkdata (entget blk)
      lay (strcat (cdr (assoc 8 blkdata)) "DELTA"); new Layer name
    ); setq
    (command "_.layer" "_make" lay "") ; will make if it doesn't exist, & set current either way; won't care if it already exists
    (entmod (subst (cons 8 lay) (assoc 8 blkdata) blkdata))
  ); repeat
); if

 

The other approaches I mentioned in Message 5 are also available.

Kent Cooper, AIA
Message 11 of 12
Lee_Mac
in reply to: Kent1Cooper


@Kent1Cooper wrote:

    (command "_.layer" "_make" lay "") ; will make if it doesn't exist, & set current either way; won't care if it already exists
    (entmod (subst (cons 8 lay) (assoc 8 blkdata) blkdata))


 There is no need to call the LAYER command as entmod will automatically add the layer to the Layer Table if it doesn't already exist.

Message 12 of 12
Kent1Cooper
in reply to: Lee_Mac


@Lee_Mac wrote:
....

 There is no need to call the LAYER command as entmod will automatically add the layer to the Layer Table if it doesn't already exist.


True -- I had found that out by accident once, a while back, but had forgotten.

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost