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
3420 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 21 of 32
ynotrobits
in reply to: Bin2009

I didn't explain thoroughly:

The dialog box would be "homemade" and not part of any standard Autocad 2006 features. If you wanted to use it, you would have to either use an existing support path or create a new support path for it and add it in. (Dialogs have .DCL extension)

Also, the templates store their information as text files so we would need to locate them somewhere.

The way I have it set up on my computer is : C:\Program Files\Dialogs

I store all my homemade dialogs, support lisps and text files in this folder.

You could store them anywhere you want, no problem---however I would need to know the file path.

Here's the way it works:

Initial setup: (After initial setup, the layer templates will retain their values)

1) You load up a template using a standard Lisp command, fill it out and then hit "OK" Once you do this, the information is stored as a text file.

2) Repeat for additional templates if necessary


Running the layer converter:

1) Load up the layer converter with a standard lisp command, check which templates you want to run and then hit "OK" to start the conversion. As the lisp runs, it will read in the template text files.

(The layer converter retains its values so if you're running the same conversion, all you would have to do is load up the converter and hit "OK")



One thing I need to bring up is that I work on a stand-alone computer and I'm not knowledgeable about network installs and how that would affect the folder locations and accessing them. I also don't know what your work situation is and whether or not you have permission to add folders.

I don't want to overwhelm you with information but do you know how to set up a menu or toolbar? (Not absolutely necessary to run the program, just makes life easier) I've included a screenshot on how I thought a menu might look for this situation.

Unfortunately, I'm leaving early today for a long weekend. If you'd like to go ahead I'll put together the dialog Monday morning and post it in the afternoon with installation instructions.

Can you tell me, did you try out the PSLTSCALE variable to adjust your paperspace LtScale and did it work correctly?

Edited by: ynotrobits on Jul 2, 2009 5:14 PM Edited by: ynotrobits on Jul 2, 2009 5:30 PM
Message 22 of 32
Bin2009
in reply to: Bin2009

Thank for your reply,

I can add my personal file under C drive. so I'd like store the file in path: C:\engineering,

I found when I set up PSLTSCALE =1, the linetype scale shows same even the viewport scale is 0.5, so now I set up the linetype scale to 0.6 for both in model and parep space.

Thanks again
Message 23 of 32
ynotrobits
in reply to: Bin2009

O.K, I'll get started on it.
Message 24 of 32
ynotrobits
in reply to: Bin2009

That took a little longer than I thought.

OK, here it is. I ran 48 layers through it on a single shot and it seemed to perform the layer and linetype conversions correctly.

I added a switch to the linetype conversion so that you can choose whether or not to keep the existing linetype or use a new one.

Since the PSLTSCALE variable is working for you, I didn't include any Linetype scale functionality. (As an FYI, I did a little research on automatically switching multiple Linetype scales between paperspaces / modelspace etc. It is possible but---for me anyway---it looked pretty complicated)

The attached zip file has all the files you need and instructions.

Let me know how it works out

Edited by: ynotrobits on Jul 7, 2009 4:57 AM Edited by: ynotrobits on Jul 7, 2009 5:00 AM
Message 25 of 32
Bin2009
in reply to: Bin2009

Thanks a lot, I am not try is yet because I am in rush to finish some other things,
I will try later and let you know the result!
Message 26 of 32
Bin2009
in reply to: Bin2009

Thanks a lot, I am not try is yet because I am in rush to finish some other things,
I will try later and let you know the result!
Message 27 of 32
brettgr
in reply to: Bin2009

I tried the lisp you created. I edited it alittle with my own layers to have it change to but when I use it, it doesn't deleted the extra layers. It says layer cannot be deleted. Below is part of the code that I am using, I didn't copy all of them since there are alot of layers in the lisp that I added. Any help would be great. maybe I copied something wrong I am not sure

 

 

{code}
( defun c:FIXMYLAYERS ( / ss_newlayer change_en )
( setq layerlist ( list ( cons "ENB_ROW-1" "ENB-ROW-1" )
( cons "Border_Condoc_DwgMgmt_Large$0$G-ANNO-TTLB" "DefPoints" )
( cons "Border_Condoc_DwgMgmt_Large$0$G-ANNO-TTLB-LOGO" "DefPoints" )
( cons "Border_Condoc_DwgMgmt_Large$0$G-ANNO-TTLB-NPLT" "DefPoints" )
( cons "Border_Condoc_DwgMgmt_Large$0$G-ANNO-TTLB-TEXT" "DefPoints" )
( cons "Border_Condoc_DwgMgmt_Small$0$G-ANNO-TTLB-LOGO" "DefPoints" )
( cons "Border_Condoc_DwgMgmt_Small$0$G-ANNO-TTLB-NPLT" "DefPoints" )
( cons "Border_Condoc_DwgMgmt_Small$0$G-ANNO-TTLB-TEXT" "DefPoints" )
( cons "DEFPPOINTS" "DefPoints" )
( cons "E-ANNO-REVC-0001" "AE NOTES" )
( cons "E-ANNO-REVC-0002" "AE NOTES" )
( cons "E-ANNO-REVS-0001" "AE NOTES" )
( cons "E-ANNO-REVS-0002" "AE NOTES" )
( cons "E-CLNG" "CEILING" )
( cons "ED-FIRE-CLNG" "AE FIRE ALARM" )
( cons "ED-LITE-SWCH" "AE ELECTRICAL" )
( cons "E-DP-2D$0$AD-BLDG" "FLOORPLAN" )
( cons "E-DP-2D$0$AE-AREA-IDEN" "ROOM TAG" )
( cons "E-DP-2D$0$AE-AREA-OCCP" "ROOM TAG" )
( cons "E-DP-2D$0$AE-DOOR" "FLOORPLAN" )
( cons "E-DP-2D$0$AE-EQPM" "EQUIPMENT" )
( cons "E-DP-2D$0$AE-EQPM-OVHD" "EQUIPMENT" )
( cons "E-DP-2D$0$AE-EQPM-UNDR" "EQUIPMENT" )
( cons "E-DP-2D$0$AE-FLOR" "MISC" )
( cons "E-DP-2D$0$AE-FLOR-CASE" "FURNITURE" )
( cons "E-DP-2D$0$AE-FLOR-CASE-OVHD" "FURNITURE" )
( cons "E-DP-2D$0$AE-FLOR-CASE-UNDR" "FURNITURE" )
( cons "E-DP-2D$0$AE-FLOR-EVTR" "MISC" )
( cons "E-DP-2D$0$AE-FLOR-OVHD" "MISC" )
( cons "E-DP-2D$0$AE-FLOR-SPCL" "MISC" )
( cons "E-DP-2D$0$AE-FLOR-STRS" "FLOORPLAN" )
( cons "E-DP-2D$0$AE-FLOR-STRS-HRAL" "FLOORPLAN" )

( cons "E-DP-2D$0$AE-AREA-IDEN" "ROOM TAG" )
( cons "AE FIRE ALARM" "AE FIRE ALARM" )

( 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}

 

Tags (1)
Message 28 of 32
Nabil_Khattab
in reply to: balisteor

Good day,

I want rename Linetype Id which has Spicial Caracturs line &, $ and # to Normal and simple name for about 450 drawings

LT_Dia.jpg

Message 29 of 32
ВeekeeCZ
in reply to: Nabil_Khattab

Try this code...

 

;Based on code by tyshofner, posted http://forums.augi.com/showthread.php?31759-Remove-0-and-everything-before-from-Layer-names/page2

(defun c:LTClean (/ LTypes l oldName badLTypes newName pos)
  (setq LTypes (vla-get-LineTypes (vla-get-ActiveDocument (vlax-get-acad-object))))
  (vlax-for l LTypes
    (setq oldName (vla-get-Name l))
    (if (and (vl-string-search "$" oldName)
	     (not (vl-string-search "|" oldName)))
      (setq badLTypes (cons oldName badLTypes))))

  (foreach oldName badLTypes
    (setq newName oldName)
    (while (setq pos (vl-string-search "$" newName))
      (setq newName (substr newName (+ pos 2))))
    (while (tblsearch "LTYPE" newName)
      (setq newName (strcat newName ".1")))
    (command "_.-RENAME" "_LT" oldName newName))
  (princ)
)
Message 30 of 32
Kent1Cooper
in reply to: ВeekeeCZ


@ВeekeeCZ wrote:

.... 

...
  (foreach oldName badLTypes
    (setq newName oldName)
    (while (setq pos (vl-string-search "$" newName))
      (setq newName (substr newName (+ pos 2))))
    (while (tblsearch "LTYPE" newName)
....

A minor streamlining suggestion:  The (vl-string-position) function allows you an option that (vl-string-search) does not, to start searching from the end, if you like, so you can find the last "$" character in one move, instead of having to step past the first one on the way there with that (while) function.  In contrast to (vl-string-search), it needs an ASCII character code rather than a string, so it works with only one character, but that's fine in this situation.  You can replace this much:

 

    (setq newName oldName)
    (while (setq pos (vl-string-search "$" newName))
      (setq newName (substr newName (+ pos 2))))

 

with just this:

 

    (setq newName (substr oldName (+ 2 (vl-string-position 36 oldName 0 T))))

 

Or, if you prefer to see the character itself in the code, so you can more easily tell what it's looking for when you come back to the code years later, you can do this:

 

    (setq newName (substr oldName (+ 2 (vl-string-position (ascii "$") oldName 0 T))))

Kent Cooper, AIA
Message 31 of 32
Nabil_Khattab
in reply to: ВeekeeCZ

I really Appreciate Your Help,
It works Nicely
Many Thanks and Have a Wonderful Day

Message 32 of 32
Nabil_Khattab
in reply to: Kent1Cooper

Many Thanks and Have a Wonderful Day

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

Post to forums  

Autodesk Design & Make Report

”Boost