Lisp to move objects to existing layers

Lisp to move objects to existing layers

Anonymous
Not applicable
5,086 Views
6 Replies
Message 1 of 7

Lisp to move objects to existing layers

Anonymous
Not applicable

Hi Lisp wizards,

Absolute acad beginner here.

I'm after a lisp that moves objects from one layer to another. 

For some back ground, we receive dwgs from a set list sub consultants that use their own layers (each subbie is different), and i want to move them onto my company's naming convention. At the moment i'm using layiso and matchprop to get the job done, but i feel this is far from the fastest way to do this. 

The layers the subbies use are consistent, so i know exactly what layer names to use. 

 

Any help is greatly appreciated.

Accepted solutions (1)
5,087 Views
6 Replies
Replies (6)
Message 2 of 7

Sea-Haven
Mentor
Mentor

Look into "-rename La" you can rather than change objects just change their layer name, you could make a script of all the layer names that need changing, the rename supports wild card rename STR* EX-STR* so makes it faster.

0 Likes
Message 3 of 7

Sea-Haven
Mentor
Mentor

Here is a dump layers change the file location. To get you started.

 

(setq fo (open "d:\\acadtemp\\layers.scr" "w"))
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(vlax-for lay (vla-get-Layers doc)
(write-line (vla-get-name lay) fo)
)
(close fo)

  

0 Likes
Message 4 of 7

dlanorh
Advisor
Advisor
Accepted solution

Try the attached lisp. This requires the layers to be in an external text file with the extension ".rly". This file contains lines in the format "OLDLAYERNAME","NEWLAYERNAME", one old,new per line. I have also attached a sample ".rly", but as the forum won't accept files with a ".rly" extension I have named it "test.rly.txt". remove the final ".txt" once downloaded.

 

The file extension can be changed in the user variables section of the lisp file. Do not precede the "." with a "*"or it will error.

This also allows you to set the path to the directory in which your files will be stored. Please note the file path format. It is a unix format that autocad understands. If you change the path please stick to using a single "/" as the path separator.

 

Once the lisp is loaded type m2lyr on the command line to run. You will be asked to select the translation file (*.rly). Everything after this is automatic. The lisp unlocks all locked layers and relocks them on exit. It will search all blocks except xrefs and translate the layers of any block entities required. It will then select all objects in the drawing and translate layers. It will also check the attributes of all attributed blocks, on the off chance that any are anonymous; this will remove the need to attsync anonymous blocks.

 

 

I am not one of the robots you're looking for

Message 5 of 7

Sea-Haven
Mentor
Mentor

Just a out there if your old like me "Please note the file path format. It is a unix format that autocad understands. If you change the path please stick to using a single "/" as the path separator".

 

Well when we had Autocad on a UNIX box the slashes had to be the opposite same as the problems with current lisp. Use \\ or /. The / can fail with spaces in directory name.

0 Likes
Message 6 of 7

Anonymous
Not applicable

exactly what i was after!

Cheers.

0 Likes
Message 7 of 7

r.boyle3GJ7C
Observer
Observer
Hello, I realise this post is 2 years old but is there a way to make this work with Wildcards so that you don't have to type the exact layer name that you want moved?
This could be useful for moving multiple layers that meet the criteria to one layer.

for example:
I have a drawing with 20 layers containing "electrical", but they have different suffixes (for example: electrcal_pit, eletrical_cable etc.), and I want to move them to one layer.

This would require 20 lines, however using a wildcard, it could be done with 1 line in the .rly file by putting a * after electrical_

Thank you 🙂
0 Likes