Jump to content

How to edit the text and the height of one line in a multiline text using lisp?


Recommended Posts

Posted

I'm trying to edit a multiline text. I previously had a single line text which got converted into a multiline text (props @Lee-mac).

 

I'm looking for ways to split the text into 2 lines, which happens if you press "enter" mid text, and then adjust the height of one of the lines. I've found very little info about Is this possible?

 

So far I've only found a way to create a multiline from scratch

 

(defun c:test () (command "_text" "_mc" "0,0" "1000" "0.0" "TextLine1");first line
(command "_text" "" "textline2");next line
(command "_text" "" "textline3");next line)

 

 

(defun c:test ()(command "_text" "_mc" "0,0" "1000" "0.0" "TextLine1" "_text" "" "textline2"
"_text" "" "textline3"))

 

None worked tough..

Posted

You will need to be clear regarding whether you are looking to create/modify Multiline Text objects (MText) or Single-line Text objects (TEXT aka DTEXT).

 

You state that your code creates multiline text, however, the code will actually create multiple lines of Single-line Text objects.

 

To change the height of one line of text within an MText object you will need to insert MText Formatting Codes within the text content - here is a partial reference for such codes.

Posted

Doing some research on the topic I noticed I can retrieve the properties of any object using visuallisp via the following:

 

(setq en(car (entsel "\n Select MText: ")))
(setq enlist(entget en))

 

At some point I noticed a parameter "1" where was the following string:

 

"P26\\P{\\H0.66667x;(0.30x0.25)}"

 

This translated exactly into the readable text in my mtext.

 

"P26

(0.30x0.25)"

 

So I tought I could change the line text to "P26\\P{\\H0.66667x;(0.30x0.25)}", and when converting into mtext it would recognize that the dimensions are in a different line. However, it doesn't for a very valid reason, I might wanna keep the special caracters in a label.

 

I've also found some complex lisps that copy every attribute from one mtext to another, this would be ideal, but it also replaces the text content which I don't want to.

 

Any hint?

Posted

Sorry Lee-mac, earlier a single line text was enough to solve the problem, but i noticed today that i would need to control a multiline since there are height changes after a paragraph.

 

Anyways I've noticed \P changes paragraph, that's exactly what I wanted, so I made a edition on your code

 

 

(defun c:ertt ( / a e o s x )
   (if (setq s (ssget "_:L" '((0 . "TEXT,MTEXT"))))
       (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) "\P" "(0." (substr (cdr a) 5 2) "x0." (substr (cdr a) 8 2) ")")) a x))    
           (command "_.txt2mtxt" e "")
    

       )
   )

 

Now it places me a "P" in the text :P

Edit: which is obvious, cause i'm editing a single line text.. duh..

Posted

There was a previous post requiring changes to mtext like what you want in this case it was coloured lines which is \C I am sure both Lee and I answered the post it just added the code for mtext changes so no probs with height per line \H. Just need to find it. maybe create as mtext then display each line with text and ht use enter as keep or else change ht till end of mtext.

 

Line1 3

line2 3

line3 5 this was changed.

line4 3

 

Thinking a bit more just enter line number and ht for mtext. Need a bit of time any one else jump in.

Posted (edited)

Found this its a start http://www.cadtutor.net/forum/showthread.php?92585-HELP-Change-only-the-colour-of-numbers-in-an-mtext&highlight=mtext

 

This is the solution now to wrapper it, just enter line no and height.

(setq mtextobj (vlax-ename->vla-object (car (entsel "\npick a mtext"))))
(setq txtstr (vla-get-textstring mtextobj))
(setq x 0)
(while (/= (setq pos (vl-string-search "\P" txtstr x)) nil)
(princ (strcat "\n" (rtos pos 2 0)))
(setq x (+ pos 1))
)

Edited by BIGAL
Posted

I dont fully understand your code BIGAL, so i've commented it, feel free to correct me anytime

 

(defun c:fff ( / x txtstr mtextobj ) ;[u]define functions and its variables[/u]

   (setq mtextobj (vlax-ename->vla-object (car (entsel "\npick a mtext")))) ;[u]assign the target multiline to mtextobj[/u]
   (setq txtstr (vla-get-textstring mtextobj)) ;[u]assign the mtext text string to variable txtstr[/u]
   (setq x 0) ;[u]define x as 0[/u]
   (while (/= (setq pos (vl-string-search "\P" txtstr x)) nil) ;[u]cycle that runs trough every character in the text string[/u]
     (princ (strcat "\n" (rtos pos 2 0))) ;[u]display something? I really dont get this line[/u]
     (setq x (+ pos 1)) ;[u]make x advance 1 character for every cycle.. but why?[/u]
    )
)

 

Anyways it replies the too few arguments error.

What I wanna do here is set a paragraph at a determined X (3), and set the height to 10 after that X. Do I really need a cycle for it?

Posted (edited)

To make it better organized I tried to edit a single mtext object the way i wanted, using the following:

 

 

 

(defun c:err3 ( / a e d o s x olddata newdata) ;a lot of unused variables, worry not

       (setq d    (car (entsel)) ;select mtext
                 x (entget d) ;assign mtext to variable x
                 a (assoc 1 x) ; assign all the value from code group 1 of the variable x to the variable a (is my interpretation correct?)
         
       )            

            (entmod (subst (cons 1 (strcat (substr (cdr a) 1 4) "\P" "{\H0.1(0." (substr (cdr a) 5 2) "x0." (substr (cdr a) 8 2)} ")")) a x)) ;add a few inbetweens inside the previous text, basically it uses substrings with other elements.
           


   (princ)
)

 

When running this there are 2 problems:

Both special codes dont work, I cant insert a paragraph with \P and I can't change the height with \Hvalue;

I tried with "" and without them.

Any idea why they dont work?? I'm pretty sure I'm doing something wrong

Edited by CesarA
Posted

edit: sorry lee mac, i've only seen your reply after this. yes you are totally right, i needed 2 backlashes :P thank you very much for all the help

 

stupid me, i found the solution. I was sure that converting dtext to mtext wouldnt recognize the special code, but it does. by modifying lee mac code this actually does it:

 

(defun c:err ( / 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 "{\\H0.15;"(substr (cdr a) 1 3)"}" "\\P{\\H0.1;(0." (substr (cdr a) 5 2) "x0." (substr (cdr a) 8 2) ")}")) a x))
           (command "_.txt2mtxt" e "")
       )
   )
   (princ)
)

 

basically the special codes are inserted in dtext, when converting to mtext it will recognize the paragraph and the height change.

Posted

Where I was headed was do txt2mtxt first then just state line 3 is to be 2.5 high line 7 is 0.5 etc. You make a new string of the mtext with correct controls by using strcat start+height+string+end}+rest of string

 

Using the example

aaaa
bbb
cccc
dddd
eeee

(setq mtextobj (vlax-ename->vla-object (car (entsel "\npick a mtext"))))
(setq txtstr (vla-get-textstring mtextobj))

returns "aaaa\\Pbbb\\Pcccc\\Pdddd\\Peeee"
now edit this to reflect 2ndrow with ht of 5

(vla-put-textstring mtextobj "aaaa{\\H5.0\\Pbbb}\\Pcccc\\Pdddd\\Peeee")
the bbb are bigger 

adding colour making bbb red
(vla-put-textstring mtextobj "aaaa{\\H5.0\\C1\\Pbbb}\\Pcccc\\Pdddd\\Peeee")

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...