Author Topic: Rename layer and add suffix  (Read 4495 times)

0 Members and 1 Guest are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Rename layer and add suffix
« Reply #15 on: February 10, 2020, 12:53:17 PM »
That code you posted is formatted incorrectly and missing a paren. Also 'old_suffix' is never defined which is why you're getting the stringp nil error. And when you create the new layer with the old layer properties no need to try and set the layer color to 256?

Here's a quick stab at what I think you're trying to accomplish.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:str56toby (/ e i lyrname n old_suffix s x)
  2.   (setq old_suffix "-56")
  3.   (if (setq s (ssget "_X" (list (cons 8 (strcat "*" old_suffix)))))
  4.     (repeat (setq i (sslength s))
  5.       (setq x       (entget (ssname s (setq i (1- i))))
  6.             lyrname (cdr (assoc 8 x))
  7.             n       (substr lyrname 1 (- (strlen lyrname) (strlen old_suffix)))
  8.       )
  9.       (if (not (tblsearch "layer" n))
  10.         (progn (setq e (entget (tblobjname "layer" lyrname)))
  11.                (entmake (subst (cons 2 n) (assoc 2 e) e))
  12.         )
  13.       )
  14.       ;; (entmod (subst (cons 8 n) (assoc 8 x) x))
  15.       ;; Put on new layer then force to color bylayer
  16.       (entmod (append x (list (cons 8 n)) '((62 . 256))))
  17.     )
  18.     (prompt "\nAll objects have been moved to secondary construction layer, Bylayer")
  19.   )
  20.   (princ)
  21. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

jlogan02

  • Bull Frog
  • Posts: 327
Re: Rename layer and add suffix
« Reply #16 on: February 11, 2020, 10:48:23 AM »
Thanks Ron,

Made some minor tweaks for two additional layer control routines. Now I have a suite of layer controls!!

Thanks for all the help folks.
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Rename layer and add suffix
« Reply #17 on: February 11, 2020, 02:49:38 PM »
Thanks Ron,

Made some minor tweaks for two additional layer control routines. Now I have a suite of layer controls!!

Thanks for all the help folks.
Glad to help  :-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC