bgator220 Posted October 2, 2010 Posted October 2, 2010 Hello Again, Ive searched all over and cannot find how to do this, but am pretty sure its out there. What code would it take to place information retrieved from lisp program to an empty mtext box. It would be even better if the user could select an existing one and append more information to it. Thanks, Brian Quote
irneb Posted October 2, 2010 Posted October 2, 2010 Replacing the text inside an MText, there are 2 basic ways. Assume you have the text you want stored in a lisp variable STR and have the MText selected and its ename stored in a lisp variable en: 1. Through entmod. (setq ed (entget en)) ;Get the DXF data list (setq ed (subst (cons 1 str) (assoc 1 ed) ed)) ;Modify the DXF list (entmod ed) ;Modify the entity 1a. That could cause problems with annotatively scaled text. For that reason I would go with this rather: (entmod (list (cons -1 en) (cons 1 str))) 2. The vla methods (also doesn't give annotative problems) (vl-load-com) ;Ensure VLisp extensions are loaded, only need to do this once per DWG. (setq eo (vlax-ename->vla-object en)) ;Get the ActiveX object of the entity (vla-put-TextString eo str) ;Change the text inside the MText To append to it, you'll need to obtain the existing value first: 1. Again watch out for annotative scaling (setq ed (entget en)) ;Get the DXF data list (setq ed (subst (cons 1 (strcat (cdr (assoc 1 ed)) str)) (assoc 1 ed) ed)) ;Modify the DXF list (entmod ed) ;Modify the entity 1a. This becomes a bit forced (setq ed (entget en)) ;Get the DXF data list (entmod (list (cons -1 en) (cons 1 (strcat (cdr (assoc 1 ed)) str)))) 2. IMO the easiest way (setq eo (vlax-ename->vla-object en)) ;Get the ActiveX object of the entity (vla-put-TextString eo (strcat (vla-get-TextString eo) str)) ;Change the text inside the MText Quote
Lee Mac Posted October 2, 2010 Posted October 2, 2010 Watch out for DXF code 3 strings also when using the entmod method. Also, vla-get-TextString will corrupt any symbols in the string (turns them into '?'). Quote
irneb Posted October 2, 2010 Posted October 2, 2010 Watch out for DXF code 3 strings also when using the entmod method. Also, vla-get-TextString will corrupt any symbols in the string (turns them into '?').So actually the vla methods aren't that great. alanjt and myself have been to'ing-an-fro'ing about it for a while. My method of choice is the 1a type as per my previous post. But you make a good point, what about MText with more than 250 characters. That would get a bit complex to do using the entmod method. Quote
Lee Mac Posted October 2, 2010 Posted October 2, 2010 But you make a good point, what about MText with more than 250 characters. That would get a bit complex to do using the entmod method. Exactly - appending to the correct DXF 3 code, then re-inserting in the correct position... EDIT: Although, after a touch of testing, it appears that the last section of the textstring is stored in DXF 1, hence the above methods may still work. Quote
alanjt Posted October 3, 2010 Posted October 3, 2010 With MText, I just take the text from entget and put it back with vla-put-textstring. Unless I know the string is going to be shorter than 250c, then if I'll just put it back with entmod. Quote
irneb Posted October 3, 2010 Posted October 3, 2010 Actually I don't see anything wrong with using the vla methods. You get the ???? characters in DText whether you use entmod or vla-put-TextString. But with MText you sometimes end up with a blank text entity if you use entmod (I think that's due to the 250 limit). As an example: (defun c:Add250+ (/ en s n) (if (setq en (entsel)) (progn (setq n 128 s "") (repeat 249 (setq s (strcat s (chr n)) n (1+ n) ) ) ;;; (vla-put-TextString (vlax-ename->vla-object (car en)) s) (entmod (list (cons -1 (car en)) (cons 1 s))) ) ) (princ) ) Quote
Lee Mac Posted October 3, 2010 Posted October 3, 2010 'Putting' is fine, its the 'getting' that causes problems - also we're talking about symols added using the MText Editor, i.e. right-click, Symbol, 'Angle' say Quote
irneb Posted October 3, 2010 Posted October 3, 2010 'Putting' is fine, its the 'getting' that causes problems - also we're talking about symols added using the MText Editor, i.e. right-click, Symbol, 'Angle' sayNot exactly:(defun c:AddMText (/ ss m n en str ed oldstr lst) (princ "\nSelect MText's: ") (if (and (setq ss (ssget '((0 . "MTEXT")))) (setq str (getString t "\nType the string to append to each: ")) ) (progn (setq m (sslength ss)) (while (>= (setq m (1- m)) 0) (setq en (ssname ss m) ed (entget en) oldstr "" ) (foreach n ed (if (member (car n) '(1 3)) (setq oldstr (strcat oldstr (cdr n))) ) ) (setq oldstr (strcat oldstr str) lst nil n 1) (while (< (+ n 249) (strlen oldstr)) (setq lst (cons (cons 3 (substr oldstr n 250)) lst) n (+ n 250) ) ) (setq lst (reverse (cons (cons 1 (substr oldstr n)) lst))) (entmod (cons (cons -1 en) lst)) ) ) ) (princ) ) All you need to do is concatenate the DXF 3 codes and the 1 code into a string variable. Although the above makes the MText blank for some reason (at least on my Vanilla 2008 ). Not sure why. 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.