SamLach Posted November 10, 2021 Posted November 10, 2021 Hi! Quick question here about assigning color. Is there a easy way to select multiple objects (I mean lines, polylines, blocks, ...) that are on different layers with their color set to "ByLayer" and assigning them the index color of the layer they are currently on so that I can ultimately have them all on a the same layer but with the original color scheme. Basically, I have a line on layer A (blue) and another line on layer B (red), both lines have the color of the layer they are on (color set to "ByLayer") and I'd like to set both of those line on layer C (green) but to have them keep their original color, blue and red. The reason behind this is I often need to import reference work in my drawing and I end up with hundreds of unnecessary layers from these other drawings so I'd like to set all of those external reference to a single layer but keep the color scheme. Perhaps I'm approaching this problem the wrong way so I'm open to suggestions to keep my drawings and layers clean and easy to work with. Thanks! Quote
CyberAngel Posted November 15, 2021 Posted November 15, 2021 My alternate suggestion is, since (I assume) you're able to alter the xref drawings, change their names so that they all begin with the letter z. That way all those layer names drop to the end of the list, so the ones you're interested in are grouped at the top. Not sure about how to change ByLayer to actual color with multiple layers (unless there's code involved), but it's easy enough with one layer. Quote
BIGAL Posted November 16, 2021 Posted November 16, 2021 Try this ; https://www.cadtutor.net/forum/topic/73977-set-selected-objects-color-to-their-current-index-color/ ; MAKE 1 LAYER BUT SAVE COLOR ; By Alanh NOV 2021 (defun c:make1lay ( / laynew layers layn ss x obj col) (setq laynew (getstring "\nEnter new layer name ")) (command "-la" "M" laynew "") (command "UNDO" "M") (vlax-for layers (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) (setq col (vla-get-color layers)) (setq layn (vla-get-name layers)) (if (= layn laynew) (princ) (progn (setq ss (ssget "X" (list (cons 8 layn)))) (if (= ss nil) (princ (strcat "\nskip " layn)) (repeat (setq x (sslength ss)) (setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1))))) (if (vlax-property-available-p obj 'layer) (vlax-put-property obj 'Layer laynew) ) (if (vlax-property-available-p obj 'color) (vlax-put-property obj 'color col) ) ) ) ) ) ) ) (c:make1lay) 1 Quote
tombu Posted November 16, 2021 Posted November 16, 2021 Rather than modifying the drawing why not just control the layers displayed in the Layer Properties Manager with Layer Filters? Check out this link: https://cadtips.cadalyst.com/layer-tools/create-filter-all-layers-except-xref-layer?q=layer-tools/create-filter-all-layers-except-xref-layer Our Civil 3D template has around 200 layers by itself so I load a collection of Layer Filters using this lisp to control the visible layers for whatever workflow I'm using at the time. ; (load "LayFilterAdd.lsp") ; ^C^C^P(or LayFilterAdd (load "LayFilterAdd.lsp"));(LayFilterAdd) ; Newer versions automatically display Xref Layer Filters **Adding Xref Layer Filter names the same as them can cause serious issues** ; Save, close and reopen the DWT or DWG for the Filters to be put into alphabetical order. (defun LayFilterAdd (/ collection names) ; (load "LFD.lsp") ; (command "C:LFD" "All*") *Layers (setq names (list "")) (if (not (vl-catch-all-error-p (setq collection (vl-catch-all-apply (function (lambda () (vla-item (vla-getextensiondictionary (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))) "ACAD_LAYERFILTERS"))) )))) ; (vlax-for item collection (setq names (cons (strcase (vla-get-name item)) names)))) (vlax-for item collection (setq names (cons (vla-get-name item) names)))) names (or(member "CALC Points" names)(command "._-layer" "filter" "new" "property" "All" "NAME==\"V-NODE-CALC\" or NAME== \"Layer*\"" "CALC Points" "X" nil)) (or(member "HATCH No xrefs" names)(command "._-layer" "filter" "new" "property" "All" "NAME==\"~*|*\" and NAME==\"*HATCH\"" "HATCH No xrefs" "X" nil)) (or(member "Linetype" names)(command "._-layer" "filter" "new" "property" "All" "LINETYPE==\"~Continuous\"" "Linetype" "X" nil)) (or(member "Lineweight" names)(command "._-layer" "filter" "new" "property" "All" "LINEWEIGHT==\"~Default\"" "Lineweight" "X" nil)) (or(member "NCS" names)(command "._-layer" "filter" "new" "property" "All" "NAME==\"[A,C,E,L,V]-*\" or NAME== \"Layer*\"" "NCS" "X" nil)) (or(member "NCS No xrefs" names)(command "._-layer" "filter" "new" "property" "All" "NAME==\"~*|*\" and NAME==\"[A,C,E,L,V]-*\" or NAME== \"Layer*\"" "NCS No xrefs" "X" nil)) (or(member "No NCS" names)(command "._-layer" "filter" "new" "property" "All" "NAME==\"~[A,C,E,L,V]-*\"" "No NCS" "X" nil)) (or(member "No NCS or xrefs" names)(command "._-layer" "filter" "new" "property" "All" "NAME==\"~*|*\" and NAME==\"~[A,C,E,L,V]-*\"" "No NCS or xrefs" "X" nil)) (or(member "No NODE" names)(command "._-layer" "filter" "new" "property" "All" "NAME==\"~*|*\" and NAME==\"[A,C,E,L,V]-*\" and NAME==\"~*-NODE*\" or NAME== \"Layer*\"" "No NODE" "X" nil)) (or(member "NODE" names)(command "._-layer" "filter" "new" "property" "All" "NAME==\"~*|*\" and NAME==\"[A,C,E,L,V]-*\" and NAME==\"*-NODE*\" or NAME== \"Layer*\"" "NODE" "X" nil)) (or(member "Profile" names)(command "._-layer" "filter" "new" "property" "All" "NAME==\"C-ROAD-PROF*\" or NAME== \"Layer*\"" "Profile" "X" nil)) (or(member "Sections" names)(command "._-layer" "filter" "new" "property" "All" "NAME==\"C-ROAD-SEC*\" or NAME== \"Layer*\"" "Sections" "X" nil)) (or(member "Topo" names)(command "._-layer" "filter" "new" "property" "All" "NAME==\"C-TOPO*\" or NAME== \"Layer*\"" "Topo" "X" nil)) (princ "Layer Filter Names » ")(princ names) ; (princ "\nSave, close and reopen the DWT or DWG for the Filters to be put into alphabetical order.") (princ) ); function (LayFilterAdd) Quick, simple & easily manageable. 1 Quote
SamLach Posted November 16, 2021 Author Posted November 16, 2021 Thank you all for your help! It gives me a good starting point to get what I'm looking for. I'll take the time to learn the basics of AutoLISP and see if I can make the changes needed to make this work with only a selection of object. 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.