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

rename layer and change linetype by LISP

31 REPLIES 31
Reply
Message 1 of 32
Bin2009
3401 Views, 31 Replies

rename layer and change linetype by LISP

I've tried to search through here for some help with this problem:

I need to do three things in a LISP routine for around 200 drawings.

First, I need rename lots of old layer to new standard layer name, like change layer name "CL-RAILWAY-0" to new layer name "CL-0".

Secondly, I need translate some layer to standard layer, like all the things on layer "CL-WATER-160" to layer "CL-0"

Last, change some linetype, like change linetype"CENTER" to "CENTERLINE".

I can do all those things by "CHECKSTANDARD" manually, but I really need someway faster and easier.

I am new to Auto lisp, hope can get help!

Thanks so much!

Edited by: Bin2009 on Jun 25, 2009 5:08 AM Edited by: Bin2009 on Jun 25, 2009 5:09 AM
31 REPLIES 31
Message 2 of 32
balisteor
in reply to: Bin2009

Here is what i made so far that should fix most of your problem.


{code}
( defun c:DOMYCHANGES ( / ss_newlayer change_en )
( if ( tblsearch "Layer" "OLDLAYERNAME" )
( command "-Layer" "Rename" "OLDAYERNAME" "NEWLAYERNAME" "" )
);i
( setq ss_newlayer ( ssget "X" ))
( while ( setq change_en ( ssname ss_newlayer 0 ))
( setq ss_newlayer ( ssdel change_en ss_newlayer ))
( if ( = "LAYERTOCHANGEFROM" ( cdr ( assoc 8 ( entget change_en ))) )
( entmod ( subst ( cons 8 "LAYERTOCHANGETO" ) ( assoc 8 ( entget change_en )) ( entget change_en ) ))
);i
);w
( princ "\nFinished:" )(princ ))
{code}




BUT
Just need some more info

In order to make it work without much user input I'll need a list of every layer that your changing from and what they need to change to. So that you dont have to do much input. Unless you would like to specify this per drawing.


And by linetype .. are you saying you need to change the linetype of objects or the linetype name?
Message 3 of 32
Bin2009
in reply to: Bin2009

Thank a lot, I'd like do those changes:

old layer name {color:#993366} new layer name{color}
ENB_ROW-1 {color:#993366}ENB-ROW-1{color}
BURIED_CABLE-120 {color:#993366}WIRE-120{color}
TOPO-BURIED_CABLE-120 {color:#993366}WIRE-120{color}
BURIED_POWER-2 {color:#993366}PWR-UG-2{color}
TOPO-FENCE-200 {color:#993366}FENCE-200{color}
HATCH-250 {color:#ff9900} {color}{color:#993366}HTCH-250{color}
......

You see, sometimes I need change two old layer name to one new layer name, I am not sure I need use layer transfer or not.

For the linetype, I need change to another kind of linetype, not just the name.

Thanks so much! Edited by: Bin2009 on Jun 25, 2009 6:41 PM
Message 4 of 32
balisteor
in reply to: Bin2009

I found that if you have attributes within blocks with a different layer than the block. that they are not affected.
But you may not have blocks like that in your drawings. I assume your just dealing with lines and such 😄

This is your solution for layers.
{code}
( defun c:FIXMYLAYERS ( / ss_newlayer change_en )
( setq layerlist ( list ( cons "ENB_ROW-1" "ENB-ROW-1" )
( cons "BURIED_CABLE-120" "WIRE-120" )
( cons "TOPO-BURIED_CABLE-120" "WIRE-120" )
( cons "BURIED_POWER-2" "PWR-UG-2" )
( cons "TOPO-FENCE-200" "FENCE-200" )
( cons "HATCH-250" "HTCH-250" ) );list
);sq
( foreach item layerlist
( if ( and ( tblsearch "Layer" ( car item ) )
( not ( tblsearch "Layer" ( cdr item ) )) );a
( command "-Layer" "Rename" ( car item ) ( cdr item ) "" )
);i
);fe

( setq ss_newlayer ( ssget "X" ))
( while ( setq change_en ( ssname ss_newlayer 0 ))
( setq ss_newlayer ( ssdel change_en ss_newlayer ))
( if ( assoc ( cdr ( assoc 8 ( entget change_en ))) layerlist )
( entmod ( subst ( cons 8 ( cdr ( assoc ( cdr ( assoc 8 ( entget change_en ))) layerlist ))) ( assoc 8 ( entget change_en )) ( entget change_en ) ))
);i
);w

( foreach item layerlist
( if ( tblsearch "Layer" ( car item ) )
( command "-Layer" "Delete" ( car item ) "" )
);i
);fe
( princ "\nFinished:" )(princ ))
{code}

If you want to fix your linetypes as well then you will also need to give me a list of old and new linetypes and I can put the changes into this code.
Message 5 of 32
Bin2009
in reply to: Bin2009

After I load the lisp, put the commed FIXMYLAYERS, my computer show like that, looks I still nedd input every new layer name?


Command: _appload FIXMYLAYERS.LSP successfully loaded.
Command:
Command:
Command: FIXMYLAYERS
-Layer
Current layer: "REFDWG-1"
Enter an option
[?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/Plot/Freeze/Thaw/LOck/Unlock/stAte]:
Rename
Invalid option keyword.
Enter an option
[?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/Plot/Freeze/Thaw/LOck/Unlock/stAte]:
*Cancel*
Message 6 of 32
balisteor
in reply to: Bin2009

No you shouldn't have to. That is strange. It should not prompt you for anything.
Let me look into it some more.
Message 7 of 32
balisteor
in reply to: Bin2009

oh.. hang on.. what version are you using?
I see now that Rename is not an option on your layer command.
Thats what the problem is. : (


We may have to take a different route for this problem.
Message 8 of 32
Bin2009
in reply to: Bin2009

Thanks, I use Autocad 2006
Message 9 of 32
balisteor
in reply to: Bin2009

OK lets see if your RENAME command works instead of LAYER command


Try this one
{code}
( defun c:FIXMYLAYERS ( / ss_newlayer change_en )
( setq layerlist ( list ( cons "ENB_ROW-1" "ENB-ROW-1" )
( cons "BURIED_CABLE-120" "WIRE-120" )
( cons "TOPO-BURIED_CABLE-120" "WIRE-120" )
( cons "BURIED_POWER-2" "PWR-UG-2" )
( cons "TOPO-FENCE-200" "FENCE-200" )
( cons "HATCH-250" "HTCH-250" ) );list
);sq
( foreach item layerlist
( if ( and ( tblsearch "Layer" ( car item ) )
( not ( tblsearch "Layer" ( cdr item ) )) );a
( command "-Rename" "LAYER" ( car item ) ( cdr item ) )
);i
);fe

( setq ss_newlayer ( ssget "X" ))
( while ( setq change_en ( ssname ss_newlayer 0 ))
( setq ss_newlayer ( ssdel change_en ss_newlayer ))
( if ( assoc ( cdr ( assoc 8 ( entget change_en ))) layerlist )
( entmod ( subst ( cons 8 ( cdr ( assoc ( cdr ( assoc 8 ( entget change_en ))) layerlist ))) ( assoc 8 ( entget change_en )) ( entget change_en ) ))
);i
);w


( princ "\nFinished:" )(princ ))
{code}
Message 10 of 32
Bin2009
in reply to: Bin2009

WOW, this one works!
You are my life saver, I almost died because those layers.
Thank you very much!
Message 11 of 32
balisteor
in reply to: Bin2009

Whew finally!
Congratulations.

Keep in mind you still need to fix your linetypes. Would you like them added.?
If so i need a list of old and new ones.

Also the newer program does not delete some of the old layers. Autocad2006 does not have a Delete layer option. So I'm trying to figure that out too.
Or you can just leave them.

I also just noticed that layerlist is not set to nil after the program completes. you can fix it by replacing the first line with this

( defun c:FIXMYLAYERS ( / layerlist ss_newlayer change_en )
Message 12 of 32
Bin2009
in reply to: Bin2009

Thanks a lot, now I go to my next question,

Secondly, I need translate some layer to standard layer, like all the things on layer "CL-WATER-160" to layer "CL-0"

After I rename some layers, there I still have some exra layers, I hope can also transfer or merge layers,
Like, I want to put all the stuff on "FENCE-3" layer to "FENCE-200", because we already have layer FENCE-200, so I can't rename FENCE-3 to FENCE-200, how can I do it?
Message 13 of 32
balisteor
in reply to: Bin2009

The program I sent you does that.

Aren't the objects that were on layer "ENB_ROW-1" changed to "ENB-ROW-1"
It doesn't just rename the layers.. It also changes the objects that were on the layers to the new layers.

IF thats not what you wanted then its wrong.
Maybe you want one program to rename layers and another to change object layers?
Message 14 of 32
balisteor
in reply to: Bin2009

If you have more objects that need their layer changed to something else then just add them into the association list.

******EXAMPLE*****
{code}
( defun c:FIXMYLAYERS ( / layerlist ss_newlayer change_en )
( setq layerlist ( list ( cons "ENB_ROW-1" "ENB-ROW-1" )
( cons "BURIED_CABLE-120" "WIRE-120" )
( cons "CL-WATER-160" "CL-0" ) ;; <---ADD OLD AND NEW LAYERS HERE!!!!!!
( cons "FENCE-3" "FENCE-200" ) ;; <---ADD OLD AND NEW LAYERS HERE!!!!!!
( cons "OLDLAYER" "NEWLAYER" );; <---ADD
( cons "OLDLAYER" "NEWLAYER" );; <---ADD
( cons "OLDLAYER" "NEWLAYER" );; <---ADD
( cons "OLDLAYER" "NEWLAYER" );; <---ADD
( cons "OLDLAYER" "NEWLAYER" );; <---ADD
( cons "OLDLAYER" "NEWLAYER" );; <---ADD
( cons "OLDLAYER" "NEWLAYER" );; <---ADD
( cons "OLDLAYER" "NEWLAYER" );; <---ADD
( cons "OLDLAYER" "NEWLAYER" );; <---ADD
( cons "OLDLAYER" "NEWLAYER" );; <---ADD
( cons "OLDLAYER" "NEWLAYER" );; <---ADD
( cons "OLDLAYER" "NEWLAYER" );; <---ADD
( cons "TOPO-BURIED_CABLE-120" "WIRE-120" )
( cons "BURIED_POWER-2" "PWR-UG-2" )
( cons "TOPO-FENCE-200" "FENCE-200" )
( cons "HATCH-250" "HTCH-250" ) );list
);sq
( foreach item layerlist
( if ( and ( tblsearch "Layer" ( car item ) )
( not ( tblsearch "Layer" ( cdr item ) )) );a
( command "-Rename" "LAYER" ( car item ) ( cdr item ) )
);i
);fe

( setq ss_newlayer ( ssget "X" ))
( while ( setq change_en ( ssname ss_newlayer 0 ))
( setq ss_newlayer ( ssdel change_en ss_newlayer ))
( if ( assoc ( cdr ( assoc 8 ( entget change_en ))) layerlist )
( entmod ( subst ( cons 8 ( cdr ( assoc ( cdr ( assoc 8 ( entget change_en ))) layerlist ))) ( assoc 8 ( entget change_en )) ( entget change_en ) ))
);i
);w


( princ "\nFinished:" )(princ ))
{code}
Message 15 of 32
Bin2009
in reply to: Bin2009

Thankvery much for your LISP, I can rename lots layers now, but I still have problem with Linelype scale set up, I have the lines in one layer have defirent Linetype scale when they in Model space and Paper space, because I use the Viewport scale is 0.5.
For example:
Layer: CL-01
Line type: Center line
in model space, Linetype scale: 1.2
in paper space, Linetype scale: 0.6

Can I use LISP do it in all the drawings?

Thanks
Message 16 of 32
balisteor
in reply to: Bin2009

Sure give me some time. I will see what i can make for you.
Do you want all of this in the same program OR are you interested in a different program?
Message 17 of 32
ynotrobits
in reply to: Bin2009

Hi Bin2009 ,



I've been watching your posts and I think I might have something for you. This particular setup requires the use of a dialog box and thus is a bit more of a hassle to install although hopefully it makes up for that by flexibility.


Here's how I thought the dialog box method could work for you (This is a technique I use for myself):


When you want to do a layer translation, you load up the "Layer Translations" dialog box which in turn calls on templates that you have set up previously.


The advantage to this is that you can set up your templates to cover various translation variables including multiple layers, lineweights and model / layouts. Note: After your initial setup, the templates hold the values until you change them. You can then include / exclude the various templates depending upon your requirements.


As you can see, you have 5 available templates and each template can hold up to 15 values. Thus, you have a total of 75 combinations available to you. (Piece of cake to add additional templates and /or additional "Layer Translation" dialogs)


I've included a screenshot of the layer translation dialog (You use this to run the lisp)


I will post an additional entry with a screenshot of the layer template and the layer templates (The templates store values that are used by the layer translation lisp)


If this is something you're interested in, let me know and I'll provide additional details.


FYI:



If you do decide you're interested in this, I do have one question which will affect how the dialog box is set up:


On your linetype conversion, do you need to convert a specific linetype name as an isolated process, i.e, Linetype A to Linetype B or do you need to have the linetype name change as part of the layer conversion process? In other words, will the linetype name change always occur as part of the layer translation process or does the linetype name change occur independently of the layer translation process?


---AJ

Edited by: ynotrobits on Jul 2, 2009 8:59 AM

Edited by: ynotrobits on Jul 2, 2009 9:00 AM Edited by: ynotrobits on Jul 2, 2009 9:02 AM
Message 18 of 32
ynotrobits
in reply to: Bin2009

Here's a layer template screenshot: Edited by: ynotrobits on Jul 2, 2009 8:58 AM
Message 19 of 32
balisteor
in reply to: Bin2009

That looks very much like what your trying to accomplish bin2009. And it may be easier to work with.
Try it out.
Message 20 of 32
Bin2009
in reply to: Bin2009

Thanks, your idea looks very good for me.
But I use AUTOCAD 2006, when I open the Layer translator dialog box, (please see attacehd screen shot), I can't find anyplace can load up the "Layer Translations" dialog box, and I don't know where can I set up the layer templates.

For me, I hope can change layer name and linetype together, because we start use new standard layer system, we need change about 40 layer name to new name, and most of the old layers linetype is good, I don't need change, I have 5 old layer's linetype need change to new linetype. I devide the process to step is because someone told me can't do those things onece time. If you can find we help me do all the things toghether, that's will be great.

Right now, I just use the LISP rename the layers, then use check standard to change linetype, afterthat , munully put linetype scale for different Model/Paper space.

Thank very much for your help!

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

Post to forums  

Autodesk Design & Make Report

”Boost