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}
Good day,
I want rename Linetype Id which has Spicial Caracturs line &, $ and # to Normal and simple name for about 450 drawings
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) )
@В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))))
I really Appreciate Your Help,
It works Nicely
Many Thanks and Have a Wonderful Day