arqi Posted February 5, 2011 Posted February 5, 2011 hey guys i have a file with 2 dozen layers each with objects in 12 different colors and i need to sort them out into layers depending on the objects color. e.g. all the objects with color "yellow" in one layer, all the objects with color "magenta" in another layer etc. can this be done with a lisp? can anyone help me i now nothing about writing lisp's Quote
BlackBox Posted February 5, 2011 Posted February 5, 2011 This should get you started: ((lambda (i / ss e c) (setq ss (ssget)) (while (setq e (ssname ss (setq i (1+ i)))) (cond ((= 1 (setq c (cdr (assoc 62 (entget e))))) ;; <- Code for red objects ) ((= 2 c) ;; <- Code for yellow objects ) ((= 3 c) ;; <- Code for green objects ) ((= 4 c) ;; <- Code for cyan objects ) ;; <- Additional colors here )) (princ)) -1) Quote
arqi Posted February 5, 2011 Author Posted February 5, 2011 thanks RenderMan i will try it out, all dough i have no experience with writing lisp, if you could fill in some of the blancks foor me that would be great! Quote
Tharwat Posted February 6, 2011 Posted February 6, 2011 This may help you and the main idea of the routine is inspired by RenderMan . (defun c:test (/ ss) (if (setq ss (ssget "_:L" )) ( (lambda (i / ss1 e col) (while (setq ss1 (ssname ss (setq i (1+ i)))) (setq e (entget ss1)) (setq col (cdr (assoc 62 e))) (cond ((eq 1 col) (entupd (cdr (assoc -1 (entmod (subst (cons 8 "Layer1")(assoc 8 e) e)))))) ((eq 2 col) (entupd (cdr (assoc -1 (entmod (subst (cons 8 "Layer2")(assoc 8 e) e)))))) ((eq 3 col) (entupd (cdr (assoc -1 (entmod (subst (cons 8 "Layer3")(assoc 8 e) e)))))) ) ) ) -1 ) (princ) ) (princ) ) Tharwat Quote
Smirnoff Posted February 6, 2011 Posted February 6, 2011 This will distribute all entities with non 'By Layer' color to layers named 'Color N'. Entities which have 'By Layer' color or on locked or frozen layers will be passed. (defun c:colay(/ aSet lCol cLay) (vl-load-com) (if(setq aSet(ssget "_X")) (progn (setq lCol(vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object)))) (foreach e(vl-remove-if 'listp(mapcar 'cadr(ssnamex aSet))) (if(setq cCol(cdr(assoc 62(entget e)))) (setq cLay(strcat "Color " (itoa cCol)) cFlg T) (setq cFlg nil) ); end if (if cFlg (progn (if(vl-catch-all-error-p (vl-catch-all-apply 'vla-Item (list lCol cLay))) (vla-Add lCol cLay) ); and if (vl-catch-all-error-p (vl-catch-all-apply 'vla-put-Layer (list e cLay))) ); end progn ); end if ); end foreach ); end progn ); end if (princ) ); end of c:colay Quote
David Bethel Posted February 6, 2011 Posted February 6, 2011 Or something fairly simple should work as well: [b][color=BLACK]([/color][/b]defun c:enc [b][color=FUCHSIA]([/color][/b]/ ss en ed clr[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]ssname ss 0[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq ed [b][color=GREEN]([/color][/b]entget en[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]if [b][color=GREEN]([/color][/b]setq clr [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 62 ed[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]entmod [b][color=BLUE]([/color][/b]subst [b][color=RED]([/color][/b]cons 8 [b][color=PURPLE]([/color][/b]strcat [color=#2f4f4f]"C"[/color] [b][color=TEAL]([/color][/b]itoa clr[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b]assoc 8 ed[b][color=RED])[/color][/b] ed[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]ssdel en ss[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] Bylayer entities are not affected. New layer name is "C" and the color number. -David Quote
Smirnoff Posted February 6, 2011 Posted February 6, 2011 (entmod (subst (cons 8 (strcat "C" (itoa clr)))(assoc 8 ed) ed)) Here is very good solution. Entmod entity and create layer at once. Quote
fixo Posted February 6, 2011 Posted February 6, 2011 Are you back, friend??? Knock my door Oleg Quote
Smirnoff Posted February 6, 2011 Posted February 6, 2011 Are you back, friend?? Hi Oleg. Yes I'm back working in AutoCAD and will sometimes coming here. Alexander. Quote
Lee Mac Posted February 6, 2011 Posted February 6, 2011 ASMI, is that you? Good to see you back if so Quote
Smirnoff Posted February 6, 2011 Posted February 6, 2011 ASMI, is that you? Yes, it's mi. Thank you Lee Mac. Quote
Lee Mac Posted February 6, 2011 Posted February 6, 2011 Great to see you around here again! Its been a long time Quote
David Bethel Posted February 6, 2011 Posted February 6, 2011 Here is very good solution. Entmod entity and create layer at once. Thanks! I try keep things simple like my mind It is good to see you back! -David Quote
arqi Posted February 6, 2011 Author Posted February 6, 2011 Or something fairly simple should work as well: [b][color=BLACK]([/color][/b]defun c:enc [b][color=FUCHSIA]([/color][/b]/ ss en ed clr[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]ssname ss 0[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq ed [b][color=GREEN]([/color][/b]entget en[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]if [b][color=GREEN]([/color][/b]setq clr [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 62 ed[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]entmod [b][color=BLUE]([/color][/b]subst [b][color=RED]([/color][/b]cons 8 [b][color=PURPLE]([/color][/b]strcat [color=#2f4f4f]"C"[/color] [b][color=TEAL]([/color][/b]itoa clr[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b]assoc 8 ed[b][color=RED])[/color][/b] ed[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]ssdel en ss[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] Bylayer entities are not affected. New layer name is "C" and the color number. -David hi david, this is working like a charm, what could i do for the "by layer" entities is there another lisp that can swap the "by layer" with the actual color?. Also could this also be done adding linetype? generating layers based on color and linetype. layers could be named like "C8 hidden, C8 continuous, C11 dashdot, C11 hidden..." thanks guys Quote
David Bethel Posted February 6, 2011 Posted February 6, 2011 For layer color and linetype - ( this could give a layer "C256-BYLAYER" ) [b][color=BLACK]([/color][/b]defun c:encl [b][color=FUCHSIA]([/color][/b]/ ss en ed nl[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]ssname ss 0[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq ed [b][color=GREEN]([/color][/b]entget en[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq nl [b][color=GREEN]([/color][/b]if [b][color=BLUE]([/color][/b]assoc 62 ed[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]strcat [color=#2f4f4f]"C"[/color] [b][color=RED]([/color][/b]itoa [b][color=PURPLE]([/color][/b]cdr [b][color=TEAL]([/color][/b]assoc 62 ed[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] [color=#2f4f4f]"C256"[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq nl [b][color=GREEN]([/color][/b]if [b][color=BLUE]([/color][/b]assoc 6 ed[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]strcat nl [color=#2f4f4f]"-"[/color] [b][color=RED]([/color][/b]cdr [b][color=PURPLE]([/color][/b]assoc 6 ed[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]strcat nl [color=#2f4f4f]"-BYLAYER"[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]entmod [b][color=GREEN]([/color][/b]subst [b][color=BLUE]([/color][/b]cons 8 nl[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]assoc 8 ed[b][color=BLUE])[/color][/b] ed[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]ssdel en ss[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] For a bylayer values I would go to the layer table and find out what color and / or linetype is currently assigned to that layer. The default being "C7-CONTINUOUS" There are probably a lot more elegant ways of doing this but who said I was elegant -David Quote
David Bethel Posted February 7, 2011 Posted February 7, 2011 With layer color and linetypes [color=#8b4513];;;CHANGED SELECTED ENTITIES TO CORRESPONDING COLOR[/color] [color=#8b4513];;;AND LINETYPE LAYER[/color] [b][color=BLACK]([/color][/b]defun c:encld [b][color=FUCHSIA]([/color][/b]/ ss en ed nl la ld nc nt ll[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]ssname ss 0[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq ed [b][color=GREEN]([/color][/b]entget en[b][color=GREEN])[/color][/b] la [b][color=GREEN]([/color][/b]cdr [b][color=BLUE]([/color][/b]assoc 8 ed[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] ld [b][color=GREEN]([/color][/b]tblsearch [color=#2f4f4f]"LAYER"[/color] la[b][color=GREEN])[/color][/b] nc [b][color=GREEN]([/color][/b]itoa [b][color=BLUE]([/color][/b]abs [b][color=RED]([/color][/b]cdr [b][color=PURPLE]([/color][/b]assoc 62 [b][color=TEAL]([/color][/b]if [b][color=OLIVE]([/color][/b]assoc 62 ed[b][color=OLIVE])[/color][/b] ed ld[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] nt [b][color=GREEN]([/color][/b]cdr [b][color=BLUE]([/color][/b]assoc 6 [b][color=RED]([/color][/b]if [b][color=PURPLE]([/color][/b]assoc 6 ed[b][color=PURPLE])[/color][/b] ed ld[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] nl [b][color=GREEN]([/color][/b]strcat [color=#2f4f4f]"C"[/color] nc [color=#2f4f4f]"-"[/color] nt[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]if [b][color=GREEN]([/color][/b]not [b][color=BLUE]([/color][/b]assoc nl ll[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [color=#8b4513];;;SETUP LAYER DATA LIST[/color] [b][color=GREEN]([/color][/b]setq ll [b][color=BLUE]([/color][/b]cons [b][color=RED]([/color][/b]list nl [color=#2f4f4f]"_C"[/color] nc[b][color=RED])[/color][/b] ll[b][color=BLUE])[/color][/b] ll [b][color=BLUE]([/color][/b]cons [b][color=RED]([/color][/b]list nl [color=#2f4f4f]"_LT"[/color] nt[b][color=RED])[/color][/b] ll[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]entmod [b][color=GREEN]([/color][/b]subst [b][color=BLUE]([/color][/b]cons 8 nl[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]assoc 8 ed[b][color=BLUE])[/color][/b] ed[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]ssdel en ss[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [color=#8b4513];;;SETUP NEW LAYER COLORS AND LINETYPES[/color] [b][color=FUCHSIA]([/color][/b]command [color=#2f4f4f]"_.LAYER"[/color][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]foreach v ll [b][color=NAVY]([/color][/b]command [b][color=MAROON]([/color][/b]nth 1 v[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]nth 2 v[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]nth 0 v[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]command [color=#2f4f4f]""[/color][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] Have Fun -David Quote
arqi Posted February 8, 2011 Author Posted February 8, 2011 With layer color and linetypes [color=#8b4513];;;CHANGED SELECTED ENTITIES TO CORRESPONDING COLOR[/color] [color=#8b4513];;;AND LINETYPE LAYER[/color] [b][color=BLACK]([/color][/b]defun c:encld [b][color=FUCHSIA]([/color][/b]/ ss en ed nl la ld nc nt ll[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]ssname ss 0[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq ed [b][color=GREEN]([/color][/b]entget en[b][color=GREEN])[/color][/b] la [b][color=GREEN]([/color][/b]cdr [b][color=BLUE]([/color][/b]assoc 8 ed[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] ld [b][color=GREEN]([/color][/b]tblsearch [color=#2f4f4f]"LAYER"[/color] la[b][color=GREEN])[/color][/b] nc [b][color=GREEN]([/color][/b]itoa [b][color=BLUE]([/color][/b]abs [b][color=RED]([/color][/b]cdr [b][color=PURPLE]([/color][/b]assoc 62 [b][color=TEAL]([/color][/b]if [b][color=OLIVE]([/color][/b]assoc 62 ed[b][color=OLIVE])[/color][/b] ed ld[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] nt [b][color=GREEN]([/color][/b]cdr [b][color=BLUE]([/color][/b]assoc 6 [b][color=RED]([/color][/b]if [b][color=PURPLE]([/color][/b]assoc 6 ed[b][color=PURPLE])[/color][/b] ed ld[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] nl [b][color=GREEN]([/color][/b]strcat [color=#2f4f4f]"C"[/color] nc [color=#2f4f4f]"-"[/color] nt[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]if [b][color=GREEN]([/color][/b]not [b][color=BLUE]([/color][/b]assoc nl ll[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [color=#8b4513];;;SETUP LAYER DATA LIST[/color] [b][color=GREEN]([/color][/b]setq ll [b][color=BLUE]([/color][/b]cons [b][color=RED]([/color][/b]list nl [color=#2f4f4f]"_C"[/color] nc[b][color=RED])[/color][/b] ll[b][color=BLUE])[/color][/b] ll [b][color=BLUE]([/color][/b]cons [b][color=RED]([/color][/b]list nl [color=#2f4f4f]"_LT"[/color] nt[b][color=RED])[/color][/b] ll[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]entmod [b][color=GREEN]([/color][/b]subst [b][color=BLUE]([/color][/b]cons 8 nl[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]assoc 8 ed[b][color=BLUE])[/color][/b] ed[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]ssdel en ss[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [color=#8b4513];;;SETUP NEW LAYER COLORS AND LINETYPES[/color] [b][color=FUCHSIA]([/color][/b]command [color=#2f4f4f]"_.LAYER"[/color][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]foreach v ll [b][color=NAVY]([/color][/b]command [b][color=MAROON]([/color][/b]nth 1 v[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]nth 2 v[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]nth 0 v[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]command [color=#2f4f4f]""[/color][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] Have Fun -David awesome david, many thanks! 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.