CAD_Noob Posted March 26, 2020 Posted March 26, 2020 (edited) I found this lisp by Kent which enable the user to pick an entity and add "-DEMO" to its layer name, change its color and linetype which is working great. Can this be modified to accept multiple selection rather than by pick only. And if i select a block if does not change the color and linetype. (defun c:DEMO (/ esel ent DLname) (while (setq esel (entsel "\nPick object to put on its Demo Layer: ")) (setq ent (car esel) DLname (strcat (cdr (assoc 8 (entget ent))) "-DEMO") ) (command "_.layer" "_make" DLname "_color" 40 "" "_ltype" "HIDDEN2" "" "" "_.chprop" ent "" "_layer" DLname "" ) ) (princ) ) Edited March 26, 2020 by CAD_Noob typo error Quote
Emmanuel Delay Posted March 26, 2020 Posted March 26, 2020 (edited) Sure, I renamed the command CLCL (defun change_layer_color_ltp ( ent / DLname) (setq ;;ent (car esel) DLname (strcat (cdr (assoc 8 (entget ent))) "-DEMO") ) (command "_.layer" "_make" DLname "_color" 40 "" "_ltype" "HIDDEN2" "" "" "_.chprop" ent "" "_layer" DLname "" ) (princ) ) (defun c:clcl ( / ss i) ;; selection (princ "\nMake selection: ") (setq ss (ssget)) ;; now perform the function for every selected entity (setq i 0) (repeat (sslength ss) (change_layer_color_ltp (ssname ss i)) (setq i (+ i 1)) ) (princ) ) Edited March 26, 2020 by Emmanuel Delay 2 1 Quote
CAD_Noob Posted March 26, 2020 Author Posted March 26, 2020 3 hours ago, Emmanuel Delay said: Sure, I renamed the command CLCL (defun change_layer_color_ltp ( ent / DLname) (setq ;;ent (car esel) DLname (strcat (cdr (assoc 8 (entget ent))) "-DEMO") ) (command "_.layer" "_make" DLname "_color" 40 "" "_ltype" "HIDDEN2" "" "" "_.chprop" ent "" "_layer" DLname "" ) (princ) ) (defun c:clcl ( / ss i) ;; selection (princ "\nMake selection: ") (setq ss (ssget)) ;; now perform the function for every selected entity (setq i 0) (repeat (sslength ss) (change_layer_color_ltp (ssname ss i)) (setq i (+ i 1)) ) (princ) ) Hi @Emmanuel Delay; thanks for this. Will try tomorrow as I do not have AutoCAD at home. 1 Quote
CAD_Noob Posted March 27, 2020 Author Posted March 27, 2020 Thanks so much! working well. Just need to edit some blocks to ByLayer for the routine to take effect. Some blocks are a bit hard to edit though there are couples of nested block Quote
CAD_Noob Posted April 1, 2020 Author Posted April 1, 2020 Hi found a bug... if the selected item happens to be in the demo layer already it again adds "-DEMO" suffix. Example : Before : A-_Door-DEMO After : A-_Door-DEMO-DEMO Quote
dlanorh Posted April 1, 2020 Posted April 1, 2020 It's not a bug, it's user error for selecting an entity on a layer with the suffix "-DEMO" A belt and braces lisp. You can't select a layer with "-DEMO" in the layer name If the layer already has an associated "-demo" layer it moves it to that layer Otherwise it creates the demo layer and moves it. (defun change_layer_color_ltp ( ent / dlname) (setq dlname (cdr (assoc 8 (entget ent)))) (cond ( (and (not (wcmatch (strcase dlname) "*-DEMO")) (setq dlname (strcat dlname "-DEMO")) (not (tblsearch "layer" dlname)) ) (command "_.layer" "_make" dlname "_color" 40 "" "_ltype" "HIDDEN2" "" "" "_.chprop" ent "" "_layer" DLname "" ) ) ( (tblsearch "layer" dlname) (command "_.chprop" ent "" "_layer" dlname "")) ) (princ) ) (defun c:clcl ( / ss i) ;; selection (princ "\nMake selection: ") (setq ss (ssget '((-4 . "<NOT") (8 . "*DEMO") (-4 . "NOT>")))) ;; now perform the function for every selected entity (setq i 0) (repeat (sslength ss) (change_layer_color_ltp (ssname ss i)) (setq i (+ i 1)) ) (princ) ) 2 Quote
CAD_Noob Posted April 2, 2020 Author Posted April 2, 2020 14 hours ago, dlanorh said: It's not a bug, it's user error for selecting an entity on a layer with the suffix "-DEMO" A belt and braces lisp. You can't select a layer with "-DEMO" in the layer name If the layer already has an associated "-demo" layer it moves it to that layer Otherwise it creates the demo layer and moves it. (defun change_layer_color_ltp ( ent / dlname) (setq dlname (cdr (assoc 8 (entget ent)))) (cond ( (and (not (wcmatch (strcase dlname) "*-DEMO")) (setq dlname (strcat dlname "-DEMO")) (not (tblsearch "layer" dlname)) ) (command "_.layer" "_make" dlname "_color" 40 "" "_ltype" "HIDDEN2" "" "" "_.chprop" ent "" "_layer" DLname "" ) ) ( (tblsearch "layer" dlname) (command "_.chprop" ent "" "_layer" dlname "")) ) (princ) ) (defun c:clcl ( / ss i) ;; selection (princ "\nMake selection: ") (setq ss (ssget '((-4 . "<NOT") (8 . "*DEMO") (-4 . "NOT>")))) ;; now perform the function for every selected entity (setq i 0) (repeat (sslength ss) (change_layer_color_ltp (ssname ss i)) (setq i (+ i 1)) ) (princ) ) Thanks for the fix, sometimes some of those demo layers are accidentally selected when windowing Quote
CAD_Noob Posted April 2, 2020 Author Posted April 2, 2020 15 hours ago, dlanorh said: It's not a bug, it's user error for selecting an entity on a layer with the suffix "-DEMO" A belt and braces lisp. You can't select a layer with "-DEMO" in the layer name If the layer already has an associated "-demo" layer it moves it to that layer Otherwise it creates the demo layer and moves it. (defun change_layer_color_ltp ( ent / dlname) (setq dlname (cdr (assoc 8 (entget ent)))) (cond ( (and (not (wcmatch (strcase dlname) "*-DEMO")) (setq dlname (strcat dlname "-DEMO")) (not (tblsearch "layer" dlname)) ) (command "_.layer" "_make" dlname "_color" 40 "" "_ltype" "HIDDEN2" "" "" "_.chprop" ent "" "_layer" DLname "" ) ) ( (tblsearch "layer" dlname) (command "_.chprop" ent "" "_layer" dlname "")) ) (princ) ) (defun c:clcl ( / ss i) ;; selection (princ "\nMake selection: ") (setq ss (ssget '((-4 . "<NOT") (8 . "*DEMO") (-4 . "NOT>")))) ;; now perform the function for every selected entity (setq i 0) (repeat (sslength ss) (change_layer_color_ltp (ssname ss i)) (setq i (+ i 1)) ) (princ) ) one last request please? exclude xref from the selection... Quote
grantm Posted June 27, 2022 Posted June 27, 2022 Hello, Great code. Can this code be updated to include adopting the source line type and line weight of the layer picked? Thanks Quote
Emmanuel Delay Posted June 28, 2022 Posted June 28, 2022 20 hours ago, grantm said: Hello, Great code. Can this code be updated to include adopting the source line type and line weight of the layer picked? Thanks That's quite another requirement. Are you happy with this: Command MCTW - select a source element (line, or whatever). - Then select a destination selection set. The destination set gets the layer, color, line type, line weight of the source. (I think it doesn't work perfectly if true color (RGB) is involved) (vl-load-com) (defun match_props ( ent layer col lt lw / ) (entmod (subst (cons 8 layer) (assoc 8 (entget ent)) (entget ent) )) ;; substitute layer ;; if this property is ByLayer, then it's empty and we have to add it. else we substitute it. Dito for follomwing If-statements (if (assoc 62 (entget ent)) (entmod (subst (cons 62 col) (assoc 62 (entget ent)) (entget ent) )) ;; substitute/add color (entmod (append (entget ent) (list (cons 62 col) ) )) ) (if (assoc 6 (entget ent)) (entmod (subst (cons 6 lt) (assoc 6 (entget ent)) (entget ent) )) ;; substitute/add line type (entmod (append (entget ent) (list (cons 6 lt) ) )) ) (if (assoc 370 (entget ent)) (entmod (subst (cons 370 lw) (assoc 370 (entget ent)) (entget ent) )) ;; substitute/add lline weight (entmod (append (entget ent) (list (cons 370 lw) ) )) ) ) ;; Match Color, line Type, and line Weight of the layer picked (defun c:MCTW ( / source layer col lt lw ss i) ;; select source, read its properties (setq source (car (entsel "\nSelect source: "))) (setq layer (cdr (assoc 8 (entget source)))) ;; layer (setq col (cdr (assoc 62 (entget source)))) ;; color (setq lt (cdr (assoc 6 (entget source)))) ;; line type (setq lw (cdr (assoc 370 (entget source)))) ;; line weight ;; select destination selection ;; selection (princ "\nMake selection: ") (setq ss (ssget)) ;; now perform the function for every selected entity (setq i 0) (repeat (sslength ss) (match_props (ssname ss i) layer col lt lw) (setq i (+ i 1)) ) (princ) ) Quote
ronjonp Posted June 28, 2022 Posted June 28, 2022 (edited) On 6/27/2022 at 8:15 AM, grantm said: Hello, Great code. Can this code be updated to include adopting the source line type and line weight of the layer picked? Thanks Here's another I've had in the toolbox for a while: (defun c:layersuffix (/ e el l f s tm) ;; RJP - 04.03.2018 (or (setq f (getenv "RJP_LayerSuffix")) (setq f (getenv "username"))) (cond ((and (setq f (cond ((/= "" (setq tm (getstring (strcat "\nEnter suffix [<" f ">]: ")))) tm) (f) ) ) (setq s (ssget ":L" (list '(-4 . "<NOT") (cons 8 (strcat "*" f)) '(-4 . "NOT>")))) ) (setenv "RJP_LayerSuffix" f) (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))) (setq el (entget (tblobjname "layer" (setq l (cdr (assoc 8 (entget e))))))) (or (tblobjname "layer" (setq nl (strcat l f))) (entmakex (subst (cons 2 nl) (assoc 2 el) el)) ) (entmod (subst (cons 8 nl) (assoc 8 (entget e)) (entget e))) ) ) ) (princ) ) Edited June 28, 2022 by ronjonp Quote
turbosocks Posted August 11, 2022 Posted August 11, 2022 This is almost exactly what I was looking for, for our Engineering group. I am terrible at manipulating LISP routines when it involves anything more than Find/Replace. I am looking to make the layer DEMO-(Layer Name) instead of (Layer Name)-DEMO. Basically prefix instead of suffix. Is there an easy way to do this? Quote
ronjonp Posted August 12, 2022 Posted August 12, 2022 23 hours ago, turbosocks said: This is almost exactly what I was looking for, for our Engineering group. I am terrible at manipulating LISP routines when it involves anything more than Find/Replace. I am looking to make the layer DEMO-(Layer Name) instead of (Layer Name)-DEMO. Basically prefix instead of suffix. Is there an easy way to do this? @turbosocks Give this a try. (defun c:layerprefix (/ e el l f s tm) ;; RJP » 2022-08-12 (or (setq f (getenv "RJP_LayerPrefix")) (setq f (getenv "username"))) (cond ((and (setq f (cond ((/= "" (setq tm (getstring (strcat "\nEnter prefix [<" f ">]: ")))) tm) (f) ) ) (setq s (ssget ":L" (list '(-4 . "<NOT") (cons 8 (strcat f "*")) '(-4 . "NOT>")))) ) (setenv "RJP_LayerPrefix" f) (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))) (setq el (entget (tblobjname "layer" (setq l (cdr (assoc 8 (entget e))))))) (or (tblobjname "layer" (setq nl (strcat f l))) (entmakex (subst (cons 2 nl) (assoc 2 el) el)) ) (entmod (subst (cons 8 nl) (assoc 8 (entget e)) (entget e))) ) ) ) (princ) ) 2 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.