CesarA 发表于 2022-7-5 18:13:29

Editing text directly (without

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
 
(please note i've started with lisp 1 hour ago)
 
Thanks for any help

CesarA 发表于 2022-7-5 18:24:22

I've finally done it,
 

(defun c:epp( / ent objmtext stroldval strnewval pname pnamee) (setq ent (car (entsel)) objmtext (vlax-ename->vla-object ent)strOldval (vlax-get-property objMText "TEXTSTRING")pname (substr strOldval 1 3)pnamee (substr strOldval 5 9 )   strnewval (strcat "\n" pname " (" pnamee ")" ))(prin1 pname)(prin1 pnamee)(vlax-put-property objmtext "TEXTSTRING" strnewval) (vlax-release-object objmtext) )
 
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?

Lee Mac 发表于 2022-7-5 18:28:19

Try the following:

(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))

CesarA 发表于 2022-7-5 18:37:10

wow.. flawless.. i will now try to match the properties of one object to all those selected, brb, thank you very much

Lee Mac 发表于 2022-7-5 18:40:20

You're welcome! - Good luck with your coding.

CesarA 发表于 2022-7-5 18:48:42

@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.

Lee Mac 发表于 2022-7-5 18:55:50

 
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.

CesarA 发表于 2022-7-5 19:05:59

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

Lee Mac 发表于 2022-7-5 19:11:55

 
Is there?
 
 
The FIND command is out of the question, as you cannot use a macro to send information to a GUI.

CesarA 发表于 2022-7-5 19:13:56

damn.. stuck on lisp :\
页: [1]
查看完整版本: Editing text directly (without