AeJay Posted March 29, 2023 Posted March 29, 2023 I have been lost as to where to place the code ";(list (cons 40 textSize)) ; add text size to modified text entity" to modify the texts to that it will be replacing. (defun c:MTP (/ cEnt elst text color ss i textSize) (if (and (setq cEnt (car (nentsel "\nSelect Source Text: "))) (member (cdr (assoc 0 (entget cEnt))) '("TEXT" "MTEXT" "ATTRIB") ) 1) (progn (setq elst (entget cEnt) text (assoc 1 elst) color (cond ((assoc 62 elst)) (T '(62 . 256)) ) textSize (cdr (assoc 40 elst)) ; get text size ) (redraw cEnt 3) (if (setq ss (ssget '((0 . "TEXT,MTEXT")))) (repeat (setq i (sslength ss)) (setq elst (entget (ssname ss (setq i (1- i))))) (entmod (subst text (assoc 1 elst) (if (assoc 62 elst) (entmod (subst color (assoc 62 elst) elst)) (append elst (list color)) ;(list (cons 40 textSize)) ; add text size to modified text entity ) ) ;(list (cons 40 textSize)) ; add text size to modified text entity ) ) ) ) ) (command "_regenall") (princ) ) Quote
AeJay Posted March 29, 2023 Author Posted March 29, 2023 I tried my new code below but I get an error of "Program ERROR: bad DXF group: 50.0". Please help. (defun c:MTP (/ cEnt elst text color ss i textSize) (if (and (setq cEnt (car (nentsel "\nSelect Source Text: "))) (member (cdr (assoc 0 (entget cEnt))) '("TEXT" "MTEXT" "ATTRIB") ) 1) (progn (setq elst (entget cEnt) text (assoc 1 elst) color (cond ((assoc 62 elst)) (T '(62 . 256)) ) textSize (cdr (assoc 40 elst)) ; get text size ) (redraw cEnt 3) (if (setq ss (ssget '((0 . "TEXT,MTEXT")))) (repeat (setq i (sslength ss)) (setq elst (entget (ssname ss (setq i (1- i))))) (entmod (subst text (assoc 1 elst) (if (assoc 62 elst) (entmod (subst color (assoc 62 elst) elst)) (append elst (list color)) ) (entmod (subst textSize (assoc 40 elst) elst)) (append elst (list textSize)) ) ) ) ) ) ) (command "_regenall") (princ) ) Quote
devitg Posted March 29, 2023 Posted March 29, 2023 (edited) 8 hours ago, AeJay said: "Program ERROR: bad DXF group: 50.0" @AeJay The error comes from this line (entmod (subst textSize (assoc 40 elst) elst)) Not know how to fix Edited March 29, 2023 by devitg Quote
pkenewell Posted March 29, 2023 Posted March 29, 2023 (edited) 1 hour ago, devitg said: 9 hours ago, AeJay said: "Program ERROR: bad DXF group: 50.0" @AeJay The error comes from this line (entmod (subst textSize (assoc 40 elst) elst)) Not know how to fix If you look earlier in the code: "textSize (cdr (assoc 40 elst))" returns only the value and not the association list. You have to plug the value back in as an equivalent dotted pair, so change: "(entmod (subst textSize (assoc 40 elst) elst))" to "(entmod (subst (cons 40 textSize) (assoc 40 elst) elst))" ALTERNATELY, you can just change: "textSize (cdr (assoc 40 elst))" to "textSize (assoc 40 elst)" Edited March 29, 2023 by pkenewell 1 Quote
tombu Posted March 29, 2023 Posted March 29, 2023 When working with entity lists save them each time you use subst to replace or append to add, entmod should only be needed once at the end. Quote
AeJay Posted March 30, 2023 Author Posted March 30, 2023 7 hours ago, pkenewell said: If you look earlier in the code: "textSize (cdr (assoc 40 elst))" returns only the value and not the association list. You have to plug the value back in as an equivalent dotted pair, so change: "(entmod (subst textSize (assoc 40 elst) elst))" to "(entmod (subst (cons 40 textSize) (assoc 40 elst) elst))" ALTERNATELY, you can just change: "textSize (cdr (assoc 40 elst))" to "textSize (assoc 40 elst)" I tried the alternative method, the error now is "too many arguments" but the interesting thing is it does copy the source text's text height but doesn't copy the source text's text and color anymore. Quote
pkenewell Posted March 30, 2023 Posted March 30, 2023 (edited) 14 hours ago, AeJay said: I tried the alternative method, the error now is "too many arguments" but the interesting thing is it does copy the source text's text height but doesn't copy the source text's text and color anymore. I found several problems and confusion with your code so I just rewrote it. Give this a try (minimally tested): NOTES: I changed variable names for 1) don't make variable names the same as an existing command, and 2) keep them shorter; they take up less memory. (defun c:MTP (/ cEnt elst txt clr ss i txtsz) (if (and (setq cEnt (car (nentsel "\nSelect Source Text: "))) (member (cdr (assoc 0 (entget cEnt))) '("TEXT" "MTEXT" "ATTRIB")) ) (progn (setq elst (entget cEnt) txt (assoc 1 elst) ; Get Text content clr (cond ((assoc 62 elst))(T '(62 . 256))); Get ACI color txtsz (assoc 40 elst) ; get text size ) (redraw cEnt 3) (if (setq ss (ssget '((0 . "TEXT,MTEXT")))) (repeat (setq i (sslength ss)) (setq elst (entget (ssname ss (setq i (1- i)))) ;Get Entity List elst (subst txt (assoc 1 elst) elst) ;Substitute test content in elist elst (if (assoc 62 elst) (subst clr (assoc 62 elst) elst)(append elst (list clr))) ;Substitute ACI color in elist elst (if (assoc 40 elst) (subst txtsz (assoc 40 elst) elst)(append elst (list txtsz))) ;substitute Text Height in elist ) (entmod elst) ; Modify new list ) ) ) ) (command "_regenall") (princ) ) Edited March 30, 2023 by pkenewell 1 1 Quote
devitg Posted March 30, 2023 Posted March 30, 2023 11 minutes ago, pkenewell said: 2) keep them shorter; they take up less memory. @pkenewell Who can worry at this times to save memory, in detriment to misunderstood what the variable mean ? Quote
pkenewell Posted March 30, 2023 Posted March 30, 2023 Just now, devitg said: Who can worry at this times to save memory, in detriment to misunderstood what the variable mean ? @devitg OK well just my preference then. I would rather keep the code shorter and the comments longer. I'm old school that way . When I started coding it made a bigger difference when there was much less memory available. Quote
devitg Posted March 30, 2023 Posted March 30, 2023 5 minutes ago, pkenewell said: @devitg OK well just my preference then. I would rather keep the code shorter and the comments longer. I'm old school that way . When I started coding it made a bigger difference when there was much less memory available. @pkenewell for sure , my first ACAD was 2.16 on a AT , circa 1991 . amber screen . 1 Quote
pkenewell Posted March 30, 2023 Posted March 30, 2023 1 minute ago, devitg said: for sure , my first ACAD was 2.16 on a AT , circa 1991 . amber screen . LOL - not far behind you. R11 for DOS. Circa 1992-93 Quote
BIGAL Posted March 31, 2023 Posted March 31, 2023 (edited) 1.4 was like the 1st Acad. Running on NEC twin 8" disc pc, Color and a green screen. Edited March 31, 2023 by BIGAL 1 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.