Author Topic: Lisp for changing layer name and color  (Read 4703 times)

0 Members and 1 Guest are viewing this topic.

MickkeJ

  • Guest
Lisp for changing layer name and color
« on: November 12, 2015, 07:13:42 AM »
Hi! I need a lisp for chnaging the name AND color of some of my layers.
I have this one that works for changing the name of the layers but I need to add the option of setting a color for each layer:

( defun c:FIXMYLAYERS ( / ss_newlayer change_en )
( setq layerlist ( list
( cons "Original layer name 1" "New layer name 1" )
( cons "Original layer name 2" "New layer name 2" )
( cons "Original layer name 3" "New layer name 3" )
);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 ))

Does anyone have any ideas about how to add the option of asigning a specific color to each layer?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Lisp for changing layer name and color
« Reply #1 on: November 12, 2015, 07:33:13 AM »
This give you any ideas ?


Command: -LAYER
Current layer:  "thislayer"
Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]: Color
New color [Truecolor/COlorbook] : 15
Enter name list of layer(s) for color 15 <thislayer>: thisLayer
Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]:



Which would translate to something like this

Code - Auto/Visual Lisp: [Select]
  1. (defun c:doit () (vl-cmdf "._Layer" "Color" 42 "thisLayer" "") (princ))
  2.  
« Last Edit: November 12, 2015, 07:52:42 AM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MickkeJ

  • Guest
Re: Lisp for changing layer name and color
« Reply #2 on: November 12, 2015, 08:25:03 AM »
I don't know how to write code but I've had this since before.
I need to be able to add the information about a specific color into each row where it also says what to change the layer name from and to.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Lisp for changing layer name and color
« Reply #3 on: November 12, 2015, 10:00:13 AM »
Perhaps try something like this

! UNTESTED

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun c:FIXMYLAYERS_42 (/ layerlist)
  3.   (setq layerlist
  4.          (list (list "Original layer name 1" "New layer name 1" 1)
  5.                (list "Original layer name 2" "New layer name 2" 2)
  6.                (list "Original layer name 3" "New layer name 3" 3)
  7.          )
  8.   )
  9.   (foreach item layerlist
  10.     (if (and (tblsearch "Layer" (car item))
  11.              (not (tblsearch "Layer" (cdr item)))
  12.         )
  13.       (vl-cmdf "-Rename" "LAYER" (car item) (cdr item))
  14.     )
  15.     (if (tblsearch "Layer" (cdr item))
  16.       (vl-cmdf "._Layer" "Color" (last item) (cdr item) "")
  17.     )
  18.   )
  19.   (princ)
  20. )
  21.  
  22.  
  23.  
  24.  
« Last Edit: November 12, 2015, 10:04:54 AM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: Lisp for changing layer name and color
« Reply #4 on: November 12, 2015, 10:06:29 AM »
Perhaps try something like this
You're so nice. :)
TheSwamp.org  (serving the CAD community since 2003)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Lisp for changing layer name and color
« Reply #5 on: November 12, 2015, 10:14:53 AM »
Perhaps try something like this
You're so nice. :)

I'm actually not, you know.
 :wink:
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Lisp for changing layer name and color
« Reply #6 on: November 12, 2015, 11:26:40 AM »
Must be on his meds today.  :2funny:
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.