AutoCAD- AutoLISP for changing layers in multiple drawings

AutoCAD- AutoLISP for changing layers in multiple drawings

max.bauerly
Contributor Contributor
1,356 Views
6 Replies
Message 1 of 7

AutoCAD- AutoLISP for changing layers in multiple drawings

max.bauerly
Contributor
Contributor

Hello all,

 

I am primarily an Autocad Electrical user but I thought this is probably a universal issue and I'm also looking for some general guidance in using AutoLISP.

 

I would like to change the layer names in multiple templates and existing drawings. I am familiar with how to do this manually. We are continuing to develop more templates and drawings so now anytime we need to make a change like this the amount of files to which the changes would need to be applied to increases. I'm assuming the answer to this question is yes but is there a way to create an AutoLISP routine that allows me to purge the existing layers of multiple drawings and import a .las file to them? If someone has already done this and would share it with me that would be appreciated but more importantly I need to figure out how to do this type of coding on my own. I have no experience with AutoLISP so I'm starting here - https://help.autodesk.com/view/OARX/2023/CHS/?guid=GUID-44DD70E7-4A84-458F-8A3A-70EC10B5F686. If anyone is aware of a better reference source or tutorials for AutoLISP, or even training for AutoLISP it would be appreciated. Thanks in advance for any help, tips or suggestions!

 

[ The subject line of this post has been edited to include the product name by @handjonathan ]

1,357 Views
6 Replies
Replies (6)
Message 2 of 7

TheCADnoob
Mentor
Mentor

I'm my experience batching with scripts is easier especially if you are not familiar with the lisp language already. That said depending on what exactly you are need to have done you may have to do it with lisp. 

 

If I were you though, I would look into some like script pro and use simple scripting if you can get away with it. Many of our less technical users are able to use scripts though even it can be tricky. But keep in mind there are limitations to what you can do in a script. 

https://www.cad-notes.com/run-a-script-on-multiple-dwg-with-scriptpro/

 

CADnoob

EESignature

Message 3 of 7

ВeekeeCZ
Consultant
Consultant

THIS site is generally recommended as a good place to start learning. HELP is surely a necessity.

Message 4 of 7

pendean
Community Legend
Community Legend
>>>...I would like to change the layer names in multiple templates and existing drawings...<<<
Do you mean LAYTRANS command is too manual to use? Or just not explored yet?

How would one static LISP file address "multiple frequent changes that only increase with time" work exactly? That would need constant editing too, is there not an option to always start with a newly defined TEMPLATE file for each different project instead? Just curious about what you've actually explored, it appears you might think LISP is more static than is will be for your needs.

Sure would be nice to have examples from you if this need to go the LISP route.
Message 5 of 7

JamesMaeding
Advisor
Advisor

@max.bauerly 

I know you wanted a lisp/script, and I have lots of those, but with those you must "open" the drawings.

That means waiting for xrefs to load and so on, even with "acadcore" special method.

This issue of layer management for multiple drawings is a HUGE one.

I have plans for a tool that scans multiple, shows a layer dialog of some kind that allows changes, then a batcher that applies those using "dbx" or "side database" methods, which take seconds and no full drawing open.

The best I have right now is in the free DWG Batcher tool I offer, which is best known for its ability to purge regapps fast.

It has other batching abilities, and they involve a text file saying what to do.

There is one to modify layer props.

One to change layer names (not xref ones!)

One to manipulate xref paths

One to change xref path type:

JamesMaeding_0-1666801915428.png

I've offered it for years and a few others have batching tools like this, such as Dotsoft.

One thing with this tool, is you can add say 10 sheets, hit Add xrefs to List, and then get a list of files involved for that planset.

You then select items, right click, and can save to folder or do various things:

JamesMaeding_1-1666802061727.png

We use this instead of etransmit, as it never fails. Etransmit digs into drawings and locks up a lot for us.

I would argue you will need this for at least one of its uses. Even just to see if your files have excess app ids.

You add the files, hit Gather File Props, and it lists the app id counts, and others in columns.

You find the "dirty" files, and just clean those for speed.

You can grab from my google drive:

Dwg Batcher 

Install instructions are in there, and really no install, just copy files.

thx


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

Message 6 of 7

max.bauerly
Contributor
Contributor

Thanks everybody!

@TheCADnoob 

I haven't got ScriptPro to do exactly what I want just yet but I'm totally glad you mentioned it. So I can utilize project wide tools on our templates I've created a project that has dwg versions of all our templates. I was manually saving each one as a .dwt after editing though so that was a real time suck. I ended up making a script that will do a few things to the dwg and then save it as a dwt so that was super helpful. I'm sure I'll use it for other stuff and I may be able to figure out how to get it to do some form of layer management at some point.

 

@ВeekeeCZ 

This site is totally awesome and I really appreciate it!

 

@pendean 

I was not aware of layertrans and I'm not sure how to utilize it. It still looks like a per drawing thing which is what I'm trying to avoid. I'm really looking for project wide or batching solutions. We also ended up deleting and adding layers which it looks like LAYERTRANS does not do. As far as AutoLISP being a solution it may or may not be. Really I don't know what AutoLISP can do so maybe I'm hoping it will do more than it can. It looks like if I'm to do this again in the future I will either need scripts and or autolisp and a batching program to run them on multiple drawings. I agree that editing the script or AutoLISP commands will take time when we need to do these layer changes but hopefully if one were to become proficient in those it would be faster than making changes drawing by drawing. We have 35 templates right now and countless wblocks. I don't think we have our layers perfected yet so we need to figure out how to do this in a repeatable time saving fashion.

 

@JamesMaeding 

Thanks for sharing. I have to admit that you said some stuff that is beyond my current Autocad mastery. I will download your tool and see what I can get out of it with my limited knowledge.

Message 7 of 7

JamesMaeding
Advisor
Advisor

@pendean 

"How would one static LISP file address "multiple frequent changes that only increase with time" work exactly?"

 

Excellent question, however I would argue a lisp that gets layers in order is the best way to handle layers, rather than a template.

Anyone who purges drawings on regular basis knows templates are really fragile.

I tell users to assume their layers will get messed up (and many other things) so have fast ways of cleaning up messes.

Now, maintaining a lisp, or sets of lisps for each drawing type is indeed intensive.

Same with maintaining templates.

My point is to OP, careful about running things through templates as you will also need fixing mechanisms later.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties