Layer renaming/creation based on XLS or CSV...

Layer renaming/creation based on XLS or CSV...

Anonymous
Not applicable
1,601 Views
6 Replies
Message 1 of 7

Layer renaming/creation based on XLS or CSV...

Anonymous
Not applicable

AutoCAD v2018

 

We are in the process of converting Microstation to AutoCAD drawings by the 1000's.  The old drawings still have Microstation level names (Level 1, Level 2, Level 3, up to Level 64 I think).  We are trying to standardize these drawings to our AutoCAD naming conventions per discipline.  Not all the old MS drawings have all the same layers, so the routine needs to first check to see if the layers exist or not.  If the old MS layers DOES exist then rename it to the NEW name AND set all the correct layer properties, if it does not, then just create the NEW corresponding layer with all the layer properties (color, line-weight, line-type, transparency, ON/OFF/FROZEN/PLOT, description, etc.)  This should allow us to run on processed and unprocessed drawings accordingly without hiccup due to some layers not existing.

 

Currently we have been running simple lisp to create/fix layers and set all the properties then running our LSP routines, via a SCRIPT using the Autodesk ScriptPro which has been working good.  This has worked, but when it comes to checking if layer exist or not, renaming layer, creating layer, I am not versed in lisp enough to do that work.

 

I think I would like lisp and xls/csv file to be same name

PIPE-LAYER.lsp

PIPE-LAYER.xls

 

Example of possible xls file

OLD, NEW, COLOR, LW, LT, ON/OFF, FROZEN/THAW, LOCK/UNLOCK, PLOT/NO PLOT, TRANS, DESC

Level 2, Border

 

Level 3, Piping, Color=3, Lineweight=.40, Linetype=Continuous, On=YES, Frozen=NO, Lock=NO,  Plot=YES, Trans=0, Description=Major Process Line

 

Level 4, Concrete, Color=4, Lineweight=.20, Linetype=Continuous, On=YES, Frozen=NO, Lock=NO,  Plot=YES, Trans=0, Description=Concrete Foundations, Slabs, Details, etc.

 

Level 5, Steel, Color=5, Lineweight=.20, Linetype=Continuous, On=YES, Frozen=NO, Lock=NO,  Plot=YES, Trans=0, Description=All NEW Structural Steel

 

Level 6, Dimensions, Color=7, Lineweight=.13, Linetype=Continuous, On=YES, Frozen=NO, Lock=NO,  Plot=YES, Trans=0, Description=All Dimensions

 

Example...

If Level 2 exist then rename to Border and then set properties

If Level 3 exist then rename to Piping and then set properties

If Level 4 does NOT exist then create Concrete layer and then set properties

If Level 5 exist then rename to Steel and then set properties

If Level 6 does NOT exist then create Dimensions layer and then set properties

 

I hope I have outlined the need, but if anyone whats to help and needs clarity please let me know.  Thank you all in advance.

 

0 Likes
1,602 Views
6 Replies
Replies (6)
Message 2 of 7

SeeMSixty7
Advisor
Advisor

The LAYTRANS command is pretty good at doing what you want. It uses it's own format for storing the layer conversions though. Essentially pull your layers from a drawing of how you want them to translate, and then use a drawing you want to convert over and then map the layers as desired and save it to a file. Then run it anytime you need.

 

Good luck,

0 Likes
Message 3 of 7

Anonymous
Not applicable

SeeMSixty: thanks for the info, I have seen this tool and for individual drawings one at a time this may do okay, its a bit clunky and awkward to use.  However I need to process hundred and thousands of drawings using ScriptPro which allows me to set a script (includes other lisps) and then point to a batch of drawings and then start and walk away... from 10 to 500+.  I think a lisp routine will better serve my process due to shear volume.

0 Likes
Message 4 of 7

SeeMSixty7
Advisor
Advisor

I believe there is a way to script it as well. I'll look back at some old files and see if I can find that for you. I've used it to process hundreds of drawings scripted and it worked like a champ once you set up the translate file. It's cleaner than writing a new function as it will work at the db level and update blocks, dim styles, table styles and ...

 

Yeah here is the function.

 

(acet-laytrans "c:/tranlatefilename.dws" nil)

 

You can find the documentation here.

https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2015/ENU/AutoCAD-AutoLISP/file... 

Message 5 of 7

Anonymous
Not applicable

Still searching for some help on this one...

0 Likes
Message 6 of 7

Sea-Haven
Mentor
Mentor

If you start with something like lee-mac parse csv this would allow you to read say a csv file and convert to a list of all the layer settings.

 

Then make a current layer name list 

 

Using a repeat for the current layer name do 1st not exist check (tblsearch "layer" lname)

else foreach in layer info list and just look for layer match when found change layer, also remove from layer detail list makes searching gradually faster as list size shrinks.

0 Likes
Message 7 of 7

SeeMSixty7
Advisor
Advisor

You can use AutoLISP to do what you are asking with some simple routines, much like @Sea-Haven has pointed out. Problem is it will become much more challenging to compensate for drawings that have both layers already defined. Blocks, text styles, dimension styles,...etc that reference on or the other will become problematic. LAYTRANS offers a really clean method for doing what you want and a great interface for establishing the rules.

 

Scenario 1. You have a drawing that just has the numeric layers in it and you just want to rename them.

(command "rename" "Layer" "Level 2" "Border")

(command "rename" "Layer" "Level 3" "Piping")

(command "rename" "Layer" "Level 4" "Concrete")

(command "rename" "Layer" "Level 5" "Steel")

(command "rename" "Layer" "Level 6" "Dimensions")

Easy and done (you can add some Layer commands to adjust the color, lweight, ltype, and status settings.

 

Scenario 2 you have existing layers as well as the layers you want them mapped to in the same drawing. mix and match.

Use some conditionals rename as above the layers that don't already exist, then use a selection set to get all the ents on Level 2 layer and move to Border, then repeat through the rest of your list. Then purge the drawing to get rid of the layers no longer needed. make sure one of them is not set to current.

 

Scenario 3 you have a mix of layers, blocks, dim styles, table styles, nested blocks, blocks with hidden attributes, blocks with attributes and no values, layers that are frozen, layers that are locked, layers that are off. You then write your code to open each block find any entities with in those blocks that are on the wrong layer, you then change them at that level to be on the correct layer. You update any attribute definitions in those blocks to be correct. You then have to run attsync on each block that you updated, and pray to god they didn't use any special rotations, move any attributes, or you simply process every block that has attributes attached, then step through them at the block insert level and change their layers there. Then step into the dimension styles, run through them and fix layer references, dig though Table Styles and do the same, step through paper space and see if you have anything in there that needs to be processed. Programmatically this is fun to do and a great challenge to help you learn all the ins and outs of a drawing database, but it can also drive you crazy when you realize how many things people can do differently, and think to yourself, "WHY ON EARTH DID THEY DO THAT?" LOL

 

Or you simply open LAYTRANS load a drawing that has the old layers, insert a drawing with all the new layers, Map the old layers to new layers, Save the file and then call (acet-laytrans "c:/tranlatefilename.dws" nil)

and you are done. You can script this across hundreds of drawings with ease. I twill be far faster than your lisp code as well as it's part of AutoCAD and the actual work is performed by ARX(C++) (I believe).

 

Good luck,

0 Likes