loudy000 Posted December 15, 2016 Share Posted December 15, 2016 (defun c:tt (/ CNT DXDT DXFDNEW DXFNEW DXFOLD ENT SSET ) (command "_.Layer" "_Make" "L-ANNO_TEXT" "_Color" "7" "" "_LType" "Continuous" "" "") (setq sset (ssget)) (setq cnt 0) (repeat (sslength sset) (setq ent (ssname sset cnt)) (setq dxdt (entget ent)) (setq dxfold (assoc 8 dxdt)) (setq dxfnew '(8 . "L-ANNO_TEXT")) (setq dxfdnew (subst dxfnew dxfold dxdt)) (entmod dxfdnew) (setq cnt (1+ cnt)) ) [color="olive"][color="olive"][color="red"](command "change" "P" "c" "" "BYLAYER" "" sset)[/color][/color][/color] (princ) ) First of all thanks to Grrr for helping me on above routine. It's working great. I just want to add 1 more command to set the layer color to "BY LAYER". I tried to add the highlighted code but it doesn't work. Any help would be appreciated. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
loudy000 Posted December 15, 2016 Author Share Posted December 15, 2016 (defun c:tt (/ CNT DXDT DXFDNEW DXFNEW DXFOLD ENT SSET ) (command "_.Layer" "_Make" "L-ANNO_TEXT" "_Color" "7" "" "_LType" "Continuous" "" "") (setq sset (ssget)) (setq cnt 0) (repeat (sslength sset) (setq ent (ssname sset cnt)) (setq dxdt (entget ent)) (setq dxfold (assoc 8 dxdt)) (setq dxfnew '(8 . "L-ANNO_TEXT")) (setq dxfdnew (subst dxfnew dxfold dxdt)) (entmod dxfdnew) (setq cnt (1+ cnt)) ) (command "CHPROP" sset "" "COLOR" "BYLAYER" "LTYPE" "BYLAYER" "") (princ) ) Got it! Quote Link to comment Share on other sites More sharing options...
Grrr Posted December 15, 2016 Share Posted December 15, 2016 You could also use a subfunction to change the entity color within the repeat loop: (defun c:tt (/ CNT DXDT DXFDNEW DXFNEW DXFOLD ENT SSET ) (command "_.Layer" "_Make" "L-ANNO_TEXT" "_Color" "7" "" "_LType" "Continuous" "" "") (setq sset (ssget "_:L")) (setq cnt 0) (repeat (sslength sset) (setq ent (ssname sset cnt)) (setq dxdt (entget ent)) (setq dxfold (assoc 8 dxdt)) (setq dxfnew '(8 . "L-ANNO_TEXT")) (setq dxfdnew (subst dxfnew dxfold dxdt)) (entmod dxfdnew) (setq cnt (1+ cnt)) (PutIndexColor ent 256) ) (princ) ) (defun PutIndexColor ( e col / enx ) (and (eq 'ENAME (type e)) (eq 'INT (type col)) (<= 0 col 256) (setq enx (vl-remove-if (function (lambda (x) (= 420 (car x)))) (entget e))) ; remove the true color if present (or (and (assoc 62 enx) (entmod (subst (cons 62 col) (assoc 62 enx) enx))) (entmod (append enx (list (cons 62 col)))) ) ) ) Quote Link to comment Share on other sites More sharing options...
StevJ Posted December 15, 2016 Share Posted December 15, 2016 Here's one that may suit your needs as a way to make things ByLayer. I didn't write it, but I use it a lot. Found it some time ago in a search, but neglected to record the author or a link back to it. (defun c:BL (/ i obj ss) (vl-load-com) (setq i -1 *doc (cond (*doc) ((vla-get-ActiveDocument (vlax-get-acad-object))))) (cond ((ssget "_:L") (vlax-for obj (setq ss (vla-get-ActiveSelectionSet *doc)) (mapcar (function (lambda (prop value) (vlax-put-property obj prop value))) '(Color Linetype Lineweight) (list acByLayer "ByLayer" acLnWtByLayer))) (vla-delete ss))) (princ)) Steve Quote Link to comment Share on other sites More sharing options...
jammie Posted December 16, 2016 Share Posted December 16, 2016 @StevJ have you tried the command setbylayer? Not sure which version of AutoCAD it was added but works similar to the code you posted. Has the advantage of working on blocks. Note the settings prompt on the commandline, can modify how the command works - setbylayer only color, linetype etc.. Quote Link to comment Share on other sites More sharing options...
StevJ Posted December 16, 2016 Share Posted December 16, 2016 @StevJ have you tried the command setbylayer? Not sure which version of AutoCAD it was added but works similar to the code you posted. Has the advantage of working on blocks. Note the settings prompt on the commandline, can modify how the command works - setbylayer only color, linetype etc.. Yes, and I'm not really a fan of it. Too many questions to answer to get results. I want to select my objects, issue the command (BL), press Enter and move on. Steve Quote Link to comment Share on other sites More sharing options...
loudy000 Posted December 17, 2016 Author Share Posted December 17, 2016 You could also use a subfunction to change the entity color within the repeat loop: (defun c:tt (/ CNT DXDT DXFDNEW DXFNEW DXFOLD ENT SSET ) (command "_.Layer" "_Make" "L-ANNO_TEXT" "_Color" "7" "" "_LType" "Continuous" "" "") (setq sset (ssget "_:L")) (setq cnt 0) (repeat (sslength sset) (setq ent (ssname sset cnt)) (setq dxdt (entget ent)) (setq dxfold (assoc 8 dxdt)) (setq dxfnew '(8 . "L-ANNO_TEXT")) (setq dxfdnew (subst dxfnew dxfold dxdt)) (entmod dxfdnew) (setq cnt (1+ cnt)) (PutIndexColor ent 256) ) (princ) ) (defun PutIndexColor ( e col / enx ) (and (eq 'ENAME (type e)) (eq 'INT (type col)) (<= 0 col 256) (setq enx (vl-remove-if (function (lambda (x) (= 420 (car x)))) (entget e))) ; remove the true color if present (or (and (assoc 62 enx) (entmod (subst (cons 62 col) (assoc 62 enx) enx))) (entmod (append enx (list (cons 62 col)))) ) ) ) Thanks Grrr as much as i wanted to but i only know basic codes ;( Quote Link to comment Share on other sites More sharing options...
loudy000 Posted December 17, 2016 Author Share Posted December 17, 2016 Here's one that may suit your needs as a way to make things ByLayer. I didn't write it, but I use it a lot.Found it some time ago in a search, but neglected to record the author or a link back to it. (defun c:BL (/ i obj ss) (vl-load-com) (setq i -1 *doc (cond (*doc) ((vla-get-ActiveDocument (vlax-get-acad-object))))) (cond ((ssget "_:L") (vlax-for obj (setq ss (vla-get-ActiveSelectionSet *doc)) (mapcar (function (lambda (prop value) (vlax-put-property obj prop value))) '(Color Linetype Lineweight) (list acByLayer "ByLayer" acLnWtByLayer))) (vla-delete ss))) (princ)) Steve Thanks StevJ i will use this in the future. Quote Link to comment Share on other sites More sharing options...
StevJ Posted December 18, 2016 Share Posted December 18, 2016 Thanks StevJ i will use this in the future. OK. It was really bothering me that I couldn't credit the author, so I found it again after a bit of searching. Written by LeeMac 02 FEB 2010 http://www.cadtutor.net/forum/showthread.php?44398-Macro Post #2 Steve Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 18, 2016 Share Posted December 18, 2016 OK. It was really bothering me that I couldn't credit the author, so I found it again after a bit of searching. Written by LeeMac 02 FEB 2010 http://www.cadtutor.net/forum/showthread.php?44398-Macro Post #2 Many thanks Steve, I appreciate your nobility. Here is a Vanilla AutoLISP version, which may offer better performance: (defun c:bl ( / i s ) (if (setq s (ssget "_:L")) (repeat (setq i (sslength s)) (entmod (append (entget (ssname s (setq i (1- i)))) '((006 . "ByLayer") (062 . 256) (370 . -1)))) ) ) (princ) ) Or, to avoid selection of objects which already have the desired properties: (defun c:bl ( / i l s ) (setq l '( (006 . "ByLayer") (062 . 256) (370 . -1) ) ) (if (setq s (ssget "_:L" (append '((-4 . "<NOT") (-4 . "<AND")) l '((-4 . "AND>") (-4 . "NOT>"))))) (repeat (setq i (sslength s)) (entmod (append (entget (ssname s (setq i (1- i)))) l))) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
Grrr Posted December 18, 2016 Share Posted December 18, 2016 Or, to avoid selection of objects which already have the desired properties: (defun c:bl ( / i l s ) (setq l '( (006 . "ByLayer") (062 . 256) (370 . -1) ) ) (if (setq s (ssget "_:L" (append '((-4 . "<NOT") (-4 . "<AND")) l '((-4 . "AND>") (-4 . "NOT>"))))) (repeat (setq i (sslength s)) (entmod (append (entget (ssname s (setq i (1- i)))) l))) ) (princ) ) This one looks very creative, thanks for posting it! Quote Link to comment Share on other sites More sharing options...
loudy000 Posted December 19, 2016 Author Share Posted December 19, 2016 Many thanks Steve, I appreciate your nobility. Here is a Vanilla AutoLISP version, which may offer better performance: (defun c:bl ( / i s ) (if (setq s (ssget "_:L")) (repeat (setq i (sslength s)) (entmod (append (entget (ssname s (setq i (1- i)))) '((006 . "ByLayer") (062 . 256) (370 . -1)))) ) ) (princ) ) Or, to avoid selection of objects which already have the desired properties: (defun c:bl ( / i l s ) (setq l '( (006 . "ByLayer") (062 . 256) (370 . -1) ) ) (if (setq s (ssget "_:L" (append '((-4 . "<NOT") (-4 . "<AND")) l '((-4 . "AND>") (-4 . "NOT>"))))) (repeat (setq i (sslength s)) (entmod (append (entget (ssname s (setq i (1- i)))) l))) ) (princ) ) Thanks Lee for another awesome code Quote Link to comment Share on other sites More sharing options...
Grrr Posted December 19, 2016 Share Posted December 19, 2016 BTW, Lee: (entmod (append (entget (ssname s (setq i (1- i)))) '((006 . "ByLayer") (062 . 256) (370 . -1)))) By looking at this I understand that its unnecessary to remove the original 6,62,370 group codes, but does this mean one simply can do this: (entmod (append (entget (ssname s (setq i (1- i)))) '((008 . "0")))) And even this (regarding if theres applied or not a index/true/book color): (entmod (append (entget (ssname s (setq i (1- i)))) '((062 . 1)))) Where for example can occur the additional GCs like: (62 . 31) (420 . 16564615) (430 . DIC COLOR GUIDE(R)$DIC 7) wheres the question smiley dammit Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 20, 2016 Share Posted December 20, 2016 This one looks very creative, thanks for posting it! Thanks Lee for another awesome code Thanks guys! BTW, Lee: (entmod (append (entget (ssname s (setq i (1- i)))) '((006 . "ByLayer") (062 . 256) (370 . -1)))) By looking at this I understand that its unnecessary to remove the original 6,62,370 group codes, but does this mean one simply can do this: (entmod (append (entget (ssname s (setq i (1- i)))) '((008 . "0")))) And even this (regarding if theres applied or not a index/true/book color): (entmod (append (entget (ssname s (setq i (1- i)))) '((062 . 1)))) Where for example can occur the additional GCs like: (62 . 31)(420 . 16564615)(430 . DIC COLOR GUIDE®$DIC 7)[/code[color=silver][size=1]][/size][/color] Indeed, it's not necessarily considered the 'correct' way to modify entity properties and this method may also fail in earlier versions of AutoCAD, but in newer releases, for DXF groups whose key should only occur once, the last such occurrence of the group will take precedence. Though, there are some exceptions to this rule, as certain DXF groups must also appear in a certain order (for example, DXF groups 70 & 90 for an LWPolyline). Quote Link to comment Share on other sites More sharing options...
Grrr Posted December 21, 2016 Share Posted December 21, 2016 Thanks for answering Lee, I performed some tests: [color=#8b4513]; Asigning Color:[/color] [color=#8b4513]; Doesn't work on multi-segment LWPOLYLINES, SPLINES, where is assigned truecolor [b][color=BLACK]([/color][/b]or colorbook[b][color=BLACK])[/color][/b] ;; but works when they have index color[/color] [color=#8b4513]; When the GC 420 is removed, works on everything[/color] [b][color=BLACK]([/color][/b]defun C:test [b][color=FUCHSIA]([/color][/b] / e enx [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]not [b][color=MAROON]([/color][/b]setq e [b][color=GREEN]([/color][/b]car [b][color=BLUE]([/color][/b]entsel [color=#2f4f4f]"\nSelect entity: "[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] e[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq enx [b][color=NAVY]([/color][/b]entget e[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq enx [b][color=NAVY]([/color][/b]vl-remove-if [b][color=MAROON]([/color][/b]function [b][color=GREEN]([/color][/b]lambda [b][color=BLUE]([/color][/b]x[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]= 420 [b][color=RED]([/color][/b]car x[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] enx[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [color=#8b4513]; <- Included[/color] [b][color=FUCHSIA]([/color][/b]entmod [b][color=NAVY]([/color][/b]append enx [b][color=MAROON]([/color][/b]list [b][color=GREEN]([/color][/b]cons 62 1[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=BLACK])[/color][/b] [color=#8b4513]; Asigning Lineweight:[/color] [b][color=BLACK]([/color][/b]defun C:test [b][color=FUCHSIA]([/color][/b] / e enx [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]not [b][color=MAROON]([/color][/b]setq e [b][color=GREEN]([/color][/b]car [b][color=BLUE]([/color][/b]entsel [color=#2f4f4f]"\nSelect entity: "[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] e[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq enx [b][color=NAVY]([/color][/b]entget e[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]entmod [b][color=NAVY]([/color][/b]append enx [b][color=MAROON]([/color][/b]list [b][color=GREEN]([/color][/b]cons 370 -1[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=BLACK])[/color][/b] [color=#8b4513]; Asigning Linetype:[/color] [b][color=BLACK]([/color][/b]defun C:test [b][color=FUCHSIA]([/color][/b] / e enx [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]not [b][color=MAROON]([/color][/b]setq e [b][color=GREEN]([/color][/b]car [b][color=BLUE]([/color][/b]entsel [color=#2f4f4f]"\nSelect entity: "[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] e[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]tblsearch [color=#2f4f4f]"LTYPE"[/color] [color=#2f4f4f]"ACAD_ISO07W100"[/color][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]setq enx [b][color=MAROON]([/color][/b]entget e[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]entmod [b][color=MAROON]([/color][/b]append enx [b][color=GREEN]([/color][/b]list [b][color=BLUE]([/color][/b]cons 6 [color=#2f4f4f]"ACAD_ISO07W100"[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=FUCHSIA])[/color][/b] [b][color=BLACK])[/color][/b] Looks like you have to remove the 420 GC in order to work on SPLINE/multisegment LWPOLYLINE entities, that have assigned truecolor or colorbook color. ( I remember once that was trying to assign index color, using vanilla and it wasn't that easy ). I'm leaving this info here, in case I have to 'reinvent the wheel' about this again. Quote Link to comment Share on other sites More sharing options...
MirelaB Posted November 11, 2017 Share Posted November 11, 2017 Hi there, I tried setbylayer to change the color of a dynamic block but for reasons unknown even I select only 3 block from design to change the color it will change also the color of others blocks not selected. I tried also these lisps but without any success. Many thanks 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.