CesarA Posted January 11, 2016 Posted January 11, 2016 (edited) I've been using a piece of code that modifies a text string of a dtext object, and then converts it into a mtext. (defun c:efg ( / a e o s x d oldd new-dxf) (if (setq s (ssget "_:L" '((0 . "TEXT")))) (repeat (setq i (sslength s)) (setq e (ssname s (setq i (1- i))) x (entget e) a (assoc 1 x) oldd (assoc 41 x) ) (entmod (subst (cons 1 (strcat "{\\H0.15;"(substr (cdr a) 1 4)"}" "{\\H0.15;(0.--" "x0.--" ")}")) a x)) (command "_.txt2mtxt" e "") ) ) (princ) ) I've noticed however that after converting it into a mtext, the identifier of the object changes, and I believe that for such reason, I cant use entmod again. So i tought of doing another identity grab after converting to mtext, like this (defun c:efg ( / a e o s x d oldd new-dxf b n m) (if (setq s (ssget "_:L" '((0 . "TEXT")))) (repeat (setq i (sslength s)) (setq e (ssname s (setq i (1- i))) ;first identity grab x (entget e) a (assoc 1 x) ) ;;;; do stuff on all the identities (entmod (subst (cons 1 (strcat "{\\H0.15;"(substr (cdr a) 1 4)"}" "{\\H0.15;(0.--" "x0.--" ")}")) a x)) (command "_.txt2mtxt" e "") (setq b (ssname n (setq i (1- i))) ;second identity grab m (entget b) oldd (assoc 41 m) new-dxf '(41 . 1.5) d (subst new-dxf oldd m) ) ;;;; modify the width of the mtext (entmod d) ) ) (princ) ) (41. is the code group for mtext width) The second grab doesn't seem to work, any hint? edit: made some corrections to the code, now i get a bad argument: lselsept I also noticed that there's a if condition that will probably be unusable since i'm queueing mtexts, so i created a separate if cycle with a condition (defun c:efg ( / a e o s x d oldd new-dxf b n m) (if (setq s (ssget "_:L" '((0 . "TEXT")))) (repeat (setq i (sslength s)) (setq e (ssname s (setq i (1- i))) ;first identity grab x (entget e) a (assoc 1 x) ) ;;;; do stuff on all the identities (entmod (subst (cons 1 (strcat "{\\H0.15;"(substr (cdr a) 1 4)"}" "{\\H0.15;(0.--" "x0.--" ")}")) a x)) (command "_.txt2mtxt" e "") ) ) (if (setq n (ssget "_:L" '((0 . "MTEXT")))) (repeat (setq i (sslength s)) (setq b (ssname n (setq i (1- i))) ;second identity grab m (entget b) oldd (assoc 41 m) new-dxf '(41 . 1.5) d (subst new-dxf oldd m) ) ;;;; modify the width of the mtext (entmod d) ) ) (princ) ) Still get the argument error Edited January 11, 2016 by CesarA Quote
Jef! Posted January 11, 2016 Posted January 11, 2016 Hi there. Your "second grab" doesn't work because... you don't grab again, you just iterate again thru the same selection set! You start by making a selection set (s) of everything you "grab" using ssget. (setq s (ssget "_:L" '((0 . "TEXT")))) Basically, your selection set contains the enames of the TEXTS you got with your ssget. When you change them to mtexts, the texts (no longer existing), your selection set containing enames to entities no longer existing is not usefull anymore. What i would do is make both entmod before passing them to the text to mtext command, liek this (defun c:efg ( / a e o s x d) (if (setq s (ssget "_:L" '((0 . "TEXT")))) (repeat (setq i (sslength s)) (setq e (ssname s (setq i (1- i))) x (entget e) a (assoc 1 x) ) (setq x (entmod (subst (cons 1 (strcat "{\\H0.15;"(substr (cdr a) 1 4)"}" "{\\H0.15;(0.--" "x0.--" ")}")) a x))); store the 1rst change into the dxf code back to x (entmod (subst '(41 . 1.5) (assoc 41 x) x));do the 2nd modification (command "_.txt2mtxt" e "") ) ) (princ) ) You also don't have to store the oldd assoc 41, as you can directly call (assoc 41 x) in your subst. I've removed "new-dxf" from your local variables as well, as you don't need to create a new variable to entmod. The lesser, the better! I hope it helped! Cheers, and happy new year! Jef! Quote
CesarA Posted January 12, 2016 Author Posted January 12, 2016 Thanks Jeff, it's very neat, but there's one problem. It doesn't work, because 41 is the codegroup of a mtext, and not a text. So when you change it while on a text, it's probably changing something else that's not the width of the mtext. That's the reason why I wanna do that change after converting to mtext. There's other problem, when I convert to mtext using that command, my autocad clearly shows "1 object removed, 1 mtext added". That's the reason why he doesn't keep the same object identification. Big problem. Anyone with a hint on how to solve this? Quote
Tharwat Posted January 12, 2016 Posted January 12, 2016 Why don't you create a new Mtext object instead of entmod 'ing the dxf codes? and if I recall correctly the entmod 'ing dxf 41 doesn't work mostly. Quote
CesarA Posted January 12, 2016 Author Posted January 12, 2016 I don't understand your question Tharwat, a new mtext object is created when I use _txt2mtxt. Also, entmod'ing is the only way I know to edit the objects (I've been around for 4 days). The creation of the new object is in fact the problem, because when I do it, the identity changes. Which means, so far, that after using that command I can't change anything on the objects I previously selected. Am I wrong? (I hope so) Quote
Tharwat Posted January 12, 2016 Posted January 12, 2016 Forget about the command txt2mtxt and use Entmake(x) to create the Mtext. Quote
CesarA Posted January 12, 2016 Author Posted January 12, 2016 I will give it a look, thanks! Oh god.. does it create a object from nothing? Very nice.. a little more programming and I'll get it up and running. I just need the coordinates and the text string from the original text, correct? Quote
Jef! Posted January 12, 2016 Posted January 12, 2016 Thanks Jeff, it's very neat, but there's one problem. It doesn't work, because 41 is the codegroup of a mtext, and not a text. So when you change it while on a text, it's probably changing something else that's not the width of the mtext. That's the reason why I wanna do that change after converting to mtext. Jef!... no double ff Well the dxf 41 on both txt/mtext is Relative X scale factor. It affects the width on any justified text/mtext, and would affect the position of a line return on a multiple line non justified mtext, which cannot be your case, since every of your mtexts are made of a single line of text translated in a mtext.. I took your digits without diging further. I'm not sure I totally understood what you are trying to make, but as Tharwat said, you can gather all you need from these texts (content, position, maybe orientation, text heigths and text styles too) and use any property suiting your needs and feed them to an entmake. You could put the mtext on the same layer as the original text, or use that oportunity to lets say, put all mtexts on a said layer, text style, to suit your actual standards. It is up to you! 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.