Ahankhah Posted September 19, 2011 Posted September 19, 2011 (edited) Hello everybody, I have written a short LISP code to do some tasks of MATCHPROP command. Here is the function: (defun MatchProp (oldobj newobj key / oldobjlist newobjlist oldassoc newassoc) (setq oldobjlist (entget oldobj)) (setq newobjlist (entget newobj)) (setq newassoc (assoc key newobjlist)) (if (setq oldassoc (assoc key oldobjlist)) (progn (if newassoc (progn (setq newobjlist (subst oldassoc newassoc newobjlist)) ) (progn; it is bylayer (setq newobjlist (append newobjlist (list oldassoc))) ) ) ) (progn; set it to bylayer (if newassoc (progn (setq newobjlist (vl-remove newassoc newobjlist)) ) ) ) ) (entmod newobjlist) ) And this is an example showing how it is called: (defun c:go() (setq oldobj (car (entsel))) (setq newobj (car (entsel))) (MatchProp oldobj newobj [color=darkslateblue][b]8[/b][/color]); [color=magenta]layer[/color] (MatchProp oldobj newobj [color=darkslateblue][b]62[/b][/color]); [color=magenta]color[/color] (MatchProp oldobj newobj [color=darkslateblue][b]420[/b][/color]); [color=magenta]color RGB[/color] (MatchProp oldobj newobj [color=darkslateblue][b]430[/b][/color]); [color=magenta]color name[/color] (MatchProp oldobj newobj [color=darkslateblue][b]6[/b][/color]); [color=magenta]linetype[/color] (MatchProp oldobj newobj [color=darkslateblue][b]48[/b][/color]); [color=magenta]linetype scale[/color] (MatchProp oldobj newobj [color=darkslateblue][b]370[/b][/color]); [color=magenta]lineweight[/color] (MatchProp oldobj newobj [color=darkslateblue][b]440[/b][/color]); [color=magenta]tranparency[/color] (MatchProp oldobj newobj [color=darkslateblue][b]390[/b][/color]); [color=magenta]plot style[/color] ) It works nice when I select an object with named color, linetype, etc. (not Bylayer), but not works vice versa at all. Could anyone checks it and show what is wrong with my program or entmod function? Thanks in advance:). Edited September 19, 2011 by Ahankhah Quote
pBe Posted September 19, 2011 Posted September 19, 2011 Thats odd. the way your code is written should work but it doesnt. Let me investigate further my friend Quote
pBe Posted September 19, 2011 Posted September 19, 2011 I gues the entity list should be the same number of elements: (defun MatchProp (oldobj newobj key / oldobjlist newobjlist oldassoc newassoc) (setq oldobjlist (entget oldobj)) (setq newobjlist (entget newobj)) (setq newassoc (assoc key newobjlist)) (if (setq oldassoc (assoc key oldobjlist)) (progn (if newassoc (progn (setq newobjlist (subst oldassoc newassoc newobjlist)) ) (progn; it is bylayer (setq newobjlist (append newobjlist (list oldassoc))) ) ) ) (progn; set it to bylayer (if newassoc (progn [color=blue](setq newobjlist (subst (cons key 256) newassoc newobjlist)) [/color] ) ) ) ) (entmod newobjlist) ) Quote
pBe Posted September 19, 2011 Posted September 19, 2011 I gues the entity list should be the same number of elements: or more? with append entmod works with no problem at all. what gives. as far as i can tell the snippet i posted above works ok with colors and linetypes, i guess additional code for the other stuff would be needed. Quote
Ahankhah Posted September 19, 2011 Author Posted September 19, 2011 Thank you very much pBe, you are right. I use your offer, as well as Properties option of CHANGE command to change other properties. Of course it is not a good solution, just good while there is no other better way. (command "_.CHANGE" obj "" "_Properties" [color=purple][b]'WhichProperty[/b][/color] "Bylayer" "") Again thank you for your time spending for my problem. Quote
David Bethel Posted September 19, 2011 Posted September 19, 2011 You would be appending with a nil: (setq newobjlist (append newobjlist (list oldassoc))) for linetype, it should be: (setq newobjlist (append newobjlist (list (cons 6 "BYLAYER")))) each group will have it's own default value. -David Quote
pBe Posted September 20, 2011 Posted September 20, 2011 You would be appending with a nil: (setq newobjlist (append newobjlist (list oldassoc))) for linetype, it should be: (setq newobjlist (append newobjlist (list (cons 6 "BYLAYER")))) each group will have it's own default value. -David Good call David Quote
Ahankhah Posted September 20, 2011 Author Posted September 20, 2011 David and pBe, thank you for your help. I list 3 line of codes as the result of our current researches on entmod function. Sets color to BYLAYER: (setq newobjlist (subst '(62 .[b] 256[/b]) newassoc newobjlist)); color of BYLAYER Sets linetype to BYLAYER: (setq newobjlist (subst '(6 . [b]"BYLAYER"[/b]) newassoc newobjlist)); linetype of BYLAYER Sets linetype scale to 1: (setq newobjlist (subst '(48 . [b]1[/b]) newassoc newobjlist)); linetype scale of 1 Quote
Ahankhah Posted September 20, 2011 Author Posted September 20, 2011 set transparency to BYLAYER: (setq newobjlist (subst '(440 . [b]"BYLAYER"[/b]) newassoc newobjlist)); transparency of BYLAYER Quote
Ahankhah Posted September 20, 2011 Author Posted September 20, 2011 set lineweight to BYLAYER: (setq newobjlist (subst '(370 . [b]-1[/b]) newassoc newobjlist)); lineweight of BYLAYER Quote
Lee Mac Posted September 20, 2011 Posted September 20, 2011 For your consideration: (defun MatchProp ( oldent newent keylist / pair1 pair2 ) (setq oldent (entget oldent) newent (entget newent) ) (foreach key keylist (if (setq pair1 (cond ( (assoc key oldent) ) ( (assoc key '( (6 . "BYLAYER") (62 . 256) (39 . 0.0) (370 . -1) ) ) ) ) ) (setq newent (if (setq pair2 (assoc key newent)) (subst pair1 pair2 newent) (append newent (list pair1)) ) ) ) ) (entmod newent) ) You would need to populate the list of default DXF values for those DXF codes omitted when set to their default values. To be called with: (MatchProp <entity> <entity> <DXF code list>) Quote
Ahankhah Posted September 21, 2011 Author Posted September 21, 2011 Lee, thank you very much. Your class of programming as always is in very higher level than mine. Quote
Lee Mac Posted September 21, 2011 Posted September 21, 2011 thank you very much. Your class of programming as always is in very higher level than mine. You're welcome Ahankhah And don't worry, you're catching me up fast Quote
ntaylor Posted August 8, 2013 Posted August 8, 2013 I have been working on some AutoLISP code to edit the colors of attributes in AutoCAD 2012, and ran into a problem where (entmod) would not update according to the modified attribute association list. The original association list did not have a group code 62, since the color was "BYLAYER". I eventually discovered that the code to revise the association list EL was causing the problem. For example, (cons (cons 62 1) EL) didn't work, but (append EL (list (cons 62 1))) did. It seems that position in the list is now crucial. Cheers... Quote
Lee Mac Posted August 8, 2013 Posted August 8, 2013 For example, (cons (cons 62 1) EL) didn't work, but (append EL (list (cons 62 1))) did. It seems that position in the list is now crucial. The position of each individual DXF group is not crucial, however, the entity type (DXF Group 0) should always come first in the DXF data list - this is likely the reason that your first example failed. For most entities, the various DXF groups can be in any order providing that the entity type appears before any other defining groups. For example, the following variations will each successfully generate a circle centered at the origin with radius 1.0, providing the entity type appears first: _$ (entmakex '((0 . "CIRCLE") (10 0.0 0.0 0.0) (40 . 1.0))) <Entity name: 7ef03c08> _$ (entmakex '((0 . "CIRCLE") (40 . 1.0) (10 0.0 0.0 0.0))) <Entity name: 7ef03c10> _$ (entmakex '((40 . 1.0) (0 . "CIRCLE") (10 0.0 0.0 0.0))) nil However, be aware that the order of some DXF groups for certain entity types is crucial, for example, where LWPolylines are concerned, DXF Group 90 must appear before DXF Group 70 otherwise the value of DXF Group 70 will be ignored: _$ (cdr (assoc 70 (entget (entmakex '((0 . "LWPOLYLINE") (100 . "AcDbEntity") (100 . "AcDbPolyline") [highlight](90 . 3) (70 . 1)[/highlight] (10 0 0) (10 1 0) (10 1 1)))))) 1 _$ (cdr (assoc 70 (entget (entmakex '((0 . "LWPOLYLINE") (100 . "AcDbEntity") (100 . "AcDbPolyline") [highlight](70 . 1) (90 . 3)[/highlight] (10 0 0) (10 1 0) (10 1 1)))))) 0 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.