I'm creating a code that edits my text objects in the same way.
I have a string with 9 characters, for example
"P01 12x34"
And all I wanna do to begin is adding a parentesis in the end and in the beginning of the numbers, like this
"P01 (12x34)"
and then convert this to mtext.
I've already found a way to convert to mtext, what i'm having problem with is editing the string, however I've found some code that actually reads the text of the object i select (which i need in this case):
(defun c:mtval( / ent objmtext stroldval
strnewval)
(setq
ent (car (entsel))
objMText
(vlax-ename->vla-object ent)
strOldval (vlax-get-property objMText
"TEXTSTRING")
strnewval (getstring T (strcat "\nNew text value
stroldval ">: "))
)
(if
strnewval
(vlax-put-property objmtext "TEXTSTRING"
strnewval)
)
(vlax-release-object objmtext)
)
However, it prompts me, with the previous text in the object, to change it. I've tried to edit the "\nNew text value
This effectively adds 2 parentesis where I wanted, without any kind of prompt.
However another problem has ocurred, it doesn't work if I have a object already selected.
Ideally it would convert all of the texts I have, adding 2 parentesis and converting to multiline. There's a code that converts multiple text objects into the same number of objects but as multiline.
(defun c:t2m ()(setq Tset (ssget '((0 . "*TEXT")))) ;filter text in selection set(setq Setlen (sslength Tset) ;setq number of entties in selection set, setq count(er) to 0Count 0) ;setq(repeat SetLen ;repeat setlen times(setq Ename (ssname Tset Count)) ;setq ename to be the "0..." entity in selection set Tset(command "_txt2mtxt" Ename "")(setq Count (+ 1 Count)) ; add 1 to Count(er)) ; Repeat (princ))
Is it possible to combine both? In a way that multiple single text objects will get the brackets as in the 1st code, and get converted into multiline objects?
(defun c:fixtxt ( / a e o s x ) (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) ) (entmod (subst (cons 1 (strcat (substr (cdr a) 1 4) "(" (substr (cdr a) 5) ")")) a x)) (command "_.txt2mtxt" e "") ) ) (princ))
@Lee Mac
Would something like this be possible to do in DIESEL or with a macro? I've noticed I will use LT soon, and lisp will not be compatible with it. Also, I couldn't find anything like a text editing possibility in macros.
Unfortunately not - a macro could perform the selection of the text object and subsequent modification to the text content, but there would be no way to retrieve the existing content of the text object and therefore no way to construct the new text string.
There's actually a diesel code that retrieves the current text
So I would only have to edit it, how can i modify the text via the command line?
Also I tought of using find and replace function, with wildcards. Most of my elements are "25x25" or "25x40" so i could make a few scripts and run trought all of them. However, the find option opens a windows, and I'm not able to define the search and replace parameters in the command line.
I've created a more appropriate topic here:
http://www.cadtutor.net/forum/showthread.php?95151-Edit-the-text-of-a-text-object-using-a-macro-diesel