Jump to content

Recommended Posts

Posted

I want to use a script to rename layers in a set of drawings, but I wan't it to just ignore layers in the script that are not present in that particular drawing, so for instance, the following won't work:

 

-rename
layer
ABC
DEF

 

as every time it arrives at a drawing that doesn't have the ABC layer, it stops to tell me so.

 

I've got around the analogous problem with blocks by using the following script:

 

(setq oldblockname "POWER")
(setq newblockname "POWER2")
(setq ss1 (ssget "X" (list (cons 2 oldblockname))))
(if ss1 (command "rename" "b" oldblockname newblockname))

 

but I can't seem to adapt it for layers.

I did think of 'making' a layer before attempting to rename it, and this works to a degree, as it doesn't seem to mind if the layer already exists, but unfortunately if the layer ABC isn't present, then DEF is, and it stops to complain that I'm trying to rename a layer to a name that already exists.

 

Any help or suggestions greatly appreciated.

 

Elliott

Posted

you could start your script by inserting a block which has all your favourite layers in - that way you make sure all the layers you call in your script are present in the drawing. regarding the opposite problem where there is already a layer named in the drawing - this sounds like a bit of a mess! i think the siplest way to do this would be to make your new layers unique, so that there is no chance of them being present before you run the script. would that be possible?

Posted

also, i assume you've considered layer translate? command LAYTRANS.

Posted
In the future,

 

Please use CODE TAGS!

 

I got you this time. :thumbsup:

 

Sorry, I'll know better next time!

Posted

Yeah I tried that but had the same problem as before of layers already existing with that name.

 

also, i assume you've considered layer translate? command LAYTRANS.

 

I'd never even heard of LAYTRANS, but I've checked it out. It probably doesn't do what I need of it, and in any case can't be run on the command line (I have 500,000 drawings to do, so it needs to be script-based for Multi-Batch to run it).

Posted

Update:

Multi-batch support have come back to me with the following code:

 

(setq oldlayername "ABC")
(setq newlayername "DEF")
(setq ss1 (ssget "X" (list (cons 8 oldlayername))))
(if ss1 (command "rename" "LA" oldlayername newlayername))

 

It works well in almost all circumstances - the only situation where it doesn't work is when the layer in question only exists within blocks. As long as at least one top-level object exists on the layer, the layer will be renamed.

Posted
in your script can you make the layer then rename it?

I tried doing it that way before, but came upon problems when the new name of a layer already existed. The code from Multi-Batch does what I need it to do, so I'm happy.

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...