webster Posted March 14, 2020 Posted March 14, 2020 Hi all, I have looked around, but I am struggling to find what I need. I am comfortable with recording, writing, running scripts however I can't find how to use quick select with scripts? Do I have to use a lisp routine to achieve what I want, then run the lisp from my script? All I really want to do in one batch is; Select all Blue items on the "Items" layer and move them to the "Blue Items" Layer Select all Red items on the "Items" layer and move them to the "Red Items" Layer Select all Green items on the "Items" layer and move them to the "Green Items" Layer If someone could point me in the right direction (or to a lisp that I can modify for instance), I would truly appreciate it. Thanks in advance. Quote
Jonathan Handojo Posted March 14, 2020 Posted March 14, 2020 AutoLISP is AutoCAD's programming language. You can search on how to use and run it. Once you've got that, load the code below and run "COLLAYER" from the command line: (defun c:collayer ( / all col ent layer len pair) (setq layer "Items" ; <--- your layer, or nil to select all layers. For multiple layers, use commas pair (list (cons acBlue "Blue Items") (cons acRed "Red Items") (cons acGreen "Green Items") ; <--- Add more below line if there are more colors ) all (ssget "_X" (if layer (list (cons 8 layer)))) ) (if all (repeat (setq len (sslength all)) (if (assoc (setq col (cdr (assoc 62 (setq ent (entget (ssname all (setq len (1- len)) ) ) ) ) ) ) pair ) (entmod (subst (cons 8 (cdr (assoc col pair))) (assoc 8 ent) ent ) ) ) ) ) ) Quote
Tickles! Posted March 14, 2020 Posted March 14, 2020 5 hours ago, Jonathan Handojo said: AutoLISP is AutoCAD's programming language. You can search on how to use and run it. Once you've got that, load the code below and run "COLLAYER" from the command line: (defun c:collayer ( / all col ent layer len pair) (setq layer "Items" ; <--- your layer, or nil to select all layers. For multiple layers, use commas pair (list (cons acBlue "Blue Items") (cons acRed "Red Items") (cons acGreen "Green Items") ; <--- Add more below line if there are more colors ) all (ssget "_X" (if layer (list (cons 8 layer)))) ) (if all (repeat (setq len (sslength all)) (if (assoc (setq col (cdr (assoc 62 (setq ent (entget (ssname all (setq len (1- len)) ) ) ) ) ) ) pair ) (entmod (subst (cons 8 (cdr (assoc col pair))) (assoc 8 ent) ent ) ) ) ) ) ) i have a question sir, how about the colors with different code? like 252... i mean, it is gray but 252 and 253 is different from each other. Quote
webster Posted March 14, 2020 Author Posted March 14, 2020 3 hours ago, Tickles! said: i have a question sir, how about the colors with different code? like 252... i mean, it is gray but 252 and 253 is different from each other. 9 hours ago, Jonathan Handojo said: AutoLISP is AutoCAD's programming language. You can search on how to use and run it. Once you've got that, load the code below and run "COLLAYER" from the command line: (defun c:collayer ( / all col ent layer len pair) (setq layer "Items" ; <--- your layer, or nil to select all layers. For multiple layers, use commas pair (list (cons acBlue "Blue Items") (cons acRed "Red Items") (cons acGreen "Green Items") ; <--- Add more below line if there are more colors ) all (ssget "_X" (if layer (list (cons 8 layer)))) ) (if all (repeat (setq len (sslength all)) (if (assoc (setq col (cdr (assoc 62 (setq ent (entget (ssname all (setq len (1- len)) ) ) ) ) ) ) pair ) (entmod (subst (cons 8 (cdr (assoc col pair))) (assoc 8 ent) ent ) ) ) ) ) ) Jonathan - Thank you so much, that is very helpful. I too am curious with Tickles Question, how do we bring in the colours by number, for instance I swapped Blue for 20, but didn't work. Quote
Jonathan Handojo Posted March 15, 2020 Posted March 15, 2020 (edited) Add (cons 20 layer_name) to the pair list. See, if you inspect acRed, acBlue, acGreen, etc... It returns you an integer. The color index of red is 1, hence acRed returns 1. acBlue returns 5, so it's really no different if you write (cons 1 "Red Items") instead of (cons acRed "Red Items). Similarly to blue, you can write (cons 5 "Blue Items) or '(5 . "Blue Items") instead of (cons acBlue "Blue Items") Edited March 15, 2020 by Jonathan Handojo Quote
webster Posted March 15, 2020 Author Posted March 15, 2020 7 hours ago, Tickles! said: i have a question sir, how about the colors with different code? like 252... i mean, it is gray but 252 and 253 is different from each other. 13 hours ago, Jonathan Handojo said: AutoLISP is AutoCAD's programming language. You can search on how to use and run it. Once you've got that, load the code below and run "COLLAYER" from the command line: (defun c:collayer ( / all col ent layer len pair) (setq layer "Items" ; <--- your layer, or nil to select all layers. For multiple layers, use commas pair (list (cons acBlue "Blue Items") (cons acRed "Red Items") (cons acGreen "Green Items") ; <--- Add more below line if there are more colors ) all (ssget "_X" (if layer (list (cons 8 layer)))) ) (if all (repeat (setq len (sslength all)) (if (assoc (setq col (cdr (assoc 62 (setq ent (entget (ssname all (setq len (1- len)) ) ) ) ) ) ) pair ) (entmod (subst (cons 8 (cdr (assoc col pair))) (assoc 8 ent) ent ) ) ) ) ) ) That is perfect, thank you! Quote
BIGAL Posted March 15, 2020 Posted March 15, 2020 (edited) For me use (While (entsel pick object for layer, (acad_colordlg 1) to pick color (entsel destination layer no hard coding. A ssget and all done. Edited March 15, 2020 by BIGAL 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.