StuboJones Posted January 26, 2011 Share Posted January 26, 2011 Evening all, I've recently received drawings through work that have been stripped onto one layer, but have different colours for each individual element in the drawing. Is it possible to select all the objects and then filter by colour as you would by line/arc/point etc? From this I would then be able to reallocate the elements to layers. Your help would be much appreciated, Cheers, Stu Quote Link to comment Share on other sites More sharing options...
BlackBox Posted January 26, 2011 Share Posted January 26, 2011 Try using the QSELECT command. :wink: Quote Link to comment Share on other sites More sharing options...
StuboJones Posted January 26, 2011 Author Share Posted January 26, 2011 Guess quick select does the job. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted January 26, 2011 Share Posted January 26, 2011 Guess quick select does the job. No worries - it's one of of my favorite tools. Quote Link to comment Share on other sites More sharing options...
alanjt Posted February 1, 2011 Share Posted February 1, 2011 LISP I wrote to include the common filters (I still use QSelect, but generally this si all I need and it's a lot faster than the QSelect menu)... eg. Command: ft Filter choice: [block/Color/Entity/Layer/linetYpe] <Layer>: FilteredSelection.LSP 1 Quote Link to comment Share on other sites More sharing options...
marmo Posted February 2, 2011 Share Posted February 2, 2011 Hi:), I have a question about this argument. For example i want selec all reds obects in a file with differents layer, differents colors bylayer or not: 1 - to selec reds objects (not by layer) i use QSELECT or FILTER commands with operator of filter = red (color n°1). 2 - to select reds objects (bylayer) i cannot use QSELECT because this command choose all colors bylayer, then i need use FILTER command with oparator filter color = 256. 256 means red color by layer (255+1). There is a way to filter with one selection all object with same displayed color (bylayer or not) ? Thanks, Quote Link to comment Share on other sites More sharing options...
Tharwat Posted February 2, 2011 Share Posted February 2, 2011 Hi:),There is a way to filter with one selection all object with same displayed color (bylayer or not) ? Thanks, Here it goes .... (sssetfirst nil (ssget "_x" '((62 . 1)))) Tharwat Quote Link to comment Share on other sites More sharing options...
marmo Posted February 2, 2011 Share Posted February 2, 2011 Hi , Tharwat tanks for reply. How can i use the code? I have copy and paste the code into command prompt, but it selec only objects with color red and not bylayer. How can i select at the same time objects reds and objects reds-bylayer?. Tanks , Quote Link to comment Share on other sites More sharing options...
Tharwat Posted February 2, 2011 Share Posted February 2, 2011 Here it goes buddy. (sssetfirst nil (ssget "_x" '((-4 . "<or") (62 . 256) (62 . 1) (-4 . "or>")))) Enjoy Quote Link to comment Share on other sites More sharing options...
irneb Posted February 2, 2011 Share Posted February 2, 2011 You could still do so through the normal Filter command (just use the OR operators, basically does what Tharwat's shown). Even the QSelect can accomplish this, but in 2 steps by checking the "Append to current selection set" at the bottom of the Quick Select dialog. Quote Link to comment Share on other sites More sharing options...
irneb Posted February 2, 2011 Share Posted February 2, 2011 Although, rereading your post ... that would still select all objects which are ByLayer (even if those layers are set to other colours). So ... try this instead: (defun ssfilter-by-color (color / lay layers) ;; Get all the layer names which are set to the color (setq lay (tblnext "LAYER" t) ;Get the 1st layer layers "" ;Initialize the layer names filter string ) (while lay ;Step through all layers ;; Check if current layer is set to color (if (= (cdr (assoc 62 lay)) color) (setq layers (strcat "," (cdr (assoc 2 lay)) layers)) ;Add to filter string ) (setq lay (tblnext "LAYER")) ;Get the next layer ) (if (= layers "") (list (cons 62 color)) (list '(-4 . "<OR") '(-4 . "<AND") (cons 8 (substr layers 2)) '(62 . 256) '(-4 . "AND>") (cons 62 color) '(-4 . "OR>") ) ) ) Then you call that thus: (sssetfirst nil (ssget "_x" (ssfilter-by-color 1))) Mind you, that would select everything on all tabs. If you only want to select the stuff on the current tab do this: (sssetfirst nil (ssget "_x" (cons (cons 410 (getvar "CTAB")) (ssfilter-by-color 1)))) Quote Link to comment Share on other sites More sharing options...
Sittingbull Posted February 2, 2011 Share Posted February 2, 2011 (edited) Hi all, I'm realy interested in this post, as i'm trying to do something similar. I'ld like to select all lines in a drawing, check what color and linetype they are, then put them in the right layer. Any help would be appreciated:wink:. Here's what i got so far: (while (setq blks (ssget "x" (list (cons 0 "insert")))) (command "explode" blks) (repeat (sslength blks)) ) (setq objss (ssget "x" (list (cons 0 "*line")))) (setq objent (entget (ssname objss 0))) (setq objcol (assoc 62 objent)) ; not working, color is bylayer (setq objlty (assoc 6 objent)) ; not working, lt bylayer (cond ((and (= objcol 2)(= objlty "continuous"))) (subst (cons 8 "ISO_LIN_UNI")(assoc 8 objent) objent)) (entmod objent) SB Edited February 2, 2011 by Sittingbull Quote Link to comment Share on other sites More sharing options...
marmo Posted February 2, 2011 Share Posted February 2, 2011 Hi guys, i made a mistake :ouch: Number 256 means "by layer" not as i wrote "red - bylayer", as do not exist color 257 (yellow - bylayer). However, there are suggestions to locate a specific color BYLAYER (red BYLAYER, yellow BYLAYER etc). Thanks for patience. Quote Link to comment Share on other sites More sharing options...
alanjt Posted February 2, 2011 Share Posted February 2, 2011 Hi guys,i made a mistake :ouch: Number 256 means "by layer" not as i wrote "red - bylayer", as do not exist color 257 (yellow - bylayer). However, there are suggestions to locate a specific color BYLAYER (red BYLAYER, yellow BYLAYER etc). Thanks for patience. (defun EntityLayerColor (entity) (if (eq (type entity) 'ENAME) (cdr (assoc 62 (tblsearch "LAYER" (cdr (assoc 8 (entget entity)))))) ) ) eg. (EntityLayerColor (car (entsel))) Quote Link to comment Share on other sites More sharing options...
Sittingbull Posted February 2, 2011 Share Posted February 2, 2011 Thx Irneb, that code of yours helps a lot. Although, i'ld like to filter by linetype aswell. f.e.: select entity if it's color is "1" and linetype is "hidden" --> put in this layer select entity if it's color is "1" and linetype is "ACAD_ISO10W100" --> put in that layer ... SB Quote Link to comment Share on other sites More sharing options...
marmo Posted February 4, 2011 Share Posted February 4, 2011 Hi, thanks guys for replies. The codes posted are very helpful. Regards, Marco Quote Link to comment Share on other sites More sharing options...
irneb Posted February 5, 2011 Share Posted February 5, 2011 Thx Irneb, that code of yours helps a lot. Although, i'ld like to filter by linetype aswell. f.e.: select entity if it's color is "1" and linetype is "hidden" --> put in this layer select entity if it's color is "1" and linetype is "ACAD_ISO10W100" --> put in that layer ... SB You're welcome. Is it only these 2 layers? Or are you looking for a method to place particular entities onto various layers depending on their properties? If so I'd not go with the selection filtering at all. Rather I'd select all lines (irrespective of their properties). Then also have a list of the target layers with their wanted properties. Next step through all lines in the selection set, check their DXF codes using entget (and of course also their ByLayer colour / linetype - use alanjt's code as sample for this). Use a cond to check which layer the current line is supposed to be moved to. Now I'd rather use entmod to modify the entity onto that layer than use something like the change command (simply because you're going to do this once for each line, i.e. this would be faster). Actually this sounds like de-ja-vu, I'm sure I've seen a similar (if not exactly the same) question in a different thread. I'll just have to search through some, can't remember exactly what thread it was. Quote Link to comment Share on other sites More sharing options...
Sittingbull Posted February 9, 2011 Share Posted February 9, 2011 Hi irneb, and thx for your reply. Indeed i was going that way at first. Hi all, I'm realy interested in this post, as i'm trying to do something similar. I'ld like to select all lines in a drawing, check what color and linetype they are, then put them in the right layer. Any help would be appreciated:wink:. ) (setq objss (ssget "x" (list (cons 0 "*line")))) (setq objent (entget (ssname objss 0))) (setq objcol (assoc 62 objent)) ; not working, color is bylayer (setq objlty (assoc 6 objent)) ; not working, lt bylayer (cond ((and (= objcol 2)(= objlty "continuous"))) (subst (cons 8 "ISO_LIN_UNI")(assoc 8 objent) objent)) (entmod objent) The problem is i'm realy a noob with lisp and can't find the correct arguments for the condition. SB Quote Link to comment Share on other sites More sharing options...
irneb Posted February 9, 2011 Share Posted February 9, 2011 The DXF codes are empty for the ByLayer colour & ltype. In which case look how alanjt gets hold of the layer's colour in post #14. So you need to check if nil was returned, is so then get the col & lty from the layer. Fortunately in lisp you can do the item extraction and checking in one go (that's one of the nice things about lisp). Basically you can do something like this: ;; ... code up to the entget (if (not (setq objcol (cdr (assoc 62 objent)))) (setq objcol (cdr (assoc 62 (tblsearch "LAYER" (cdr (assoc 8 objent)))))) ) (if (not (setq objlty (cdr (assoc 6 objent)))) (setq objlty (cdr (assoc 6 (tblsearch "LAYER" (cdr (assoc 8 objent)))))) ) ;; ... further code Quote Link to comment Share on other sites More sharing options...
Sittingbull Posted February 9, 2011 Share Posted February 9, 2011 I added your code to mine, but it's not going as i expected. (setq objss (ssget "x" (list (cons 0 "*line")))) (setq objent (entget (ssname objss 0))) (if (not (setq objcol (cdr (assoc 62 objent)))) (setq objcol (cdr (assoc 62 (tblsearch "LAYER" (cdr (assoc 8 objent)))))) ) (if (not (setq objlty (cdr (assoc 6 objent)))) (setq objlty (cdr (assoc 6 (tblsearch "LAYER" (cdr (assoc 8 objent)))))) ) (cond ((and (= objcol 2)(= objlty "continuous"))) (subst (cons 8 "ISO_LIN_UNI")(assoc 8 objent) objent)) (entmod objent) It's prolly me, but i think i lost you somewhere. Could it be that your previous code means... (if (not (setq objcol (cdr (assoc 62 objent)))) ; if objcol is not the color of objent ? ; then (setq objcol (cdr (assoc 62 (tblsearch "LAYER" (cdr (assoc 8 objent)))))) ; associate the color from the layer of objent to objcol ? I thought it would have been a very simple code. Maybe i didn't explain myself in a comprehensive way, or maybe i'm not getting what you're trying to say. But i 'm not sure this code is what i need. What i'm trying to do: 1. Select all *line objects 2. Filter them with conditions like: color "1", and linetype "continuous" --> put in layer "blablabla" color "1", and linetype "hidden" --> put in layer "blablabla" color "1", and linetype "center" --> put in layer "blablabla" color "2", and linetype "continuous" --> put in layer "blablabla" color "2", and linetype "hidden" --> put in layer "blablabla" color "2", and linetype "center" --> put in layer "blablabla" ... The reason why your code whas interesting to me is because it selects an entity by color, even if this color is the layer color and not the obj color. After that i just needed to check what linetype the sset was in and choose a layer to assign to it(i guess...). The morons who have drawed this library have used any kind of layer to draw any parts and then adjusted the properties. Some lines have a color, some have their color set "bylayer" and are in the correct layer, some are in the wrong layer. It's like you would draw an entire drawing in layer "0", and then change some of the lines to a correct layer with correct color, and other lines you would leave them in layer "0" but change the properties. It's a mess. I need to get those lines in the correct layer again. Then i can change the color properties of "all" lines back to "bylayer". The only thing i can rely on as a reference, is the color of the lines, regardless of the layer they are in, whether or not their color is set to "color n" or "bylayer". Sorry if i got you confused:oops:. SB Quote Link to comment Share on other sites More sharing options...
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.