Jump to content
Arepo

MText command in LISP

Recommended Posts

Arepo

I am trying to write a routine to "simulate" MText command in lisp using predefined Text Height (2.0mm in this case for 1:1 scale) and text Style. I started with this code:

 

(defun C:test (/ Height Style)
(setvar "cmdecho" 1)
(setq Height (* (getvar "DIMSCALE") 2.0 ))
(setq Style "My_Style")
(command "._MTEXT" pause "H" Height "S" Style pause)
	(princ)
)

 

The text style seems to work but the Text Height doesn't change.

Could anyone help please?

Edited by Arepo

Share this post


Link to post
Share on other sites
rickh

Is (getvar "textsize") what you need instead of dimscale? You also have to ensure the text style used does not have a predefined height.

From F1 help for textsize:

Sets the default height for new text objects drawn with the current text style.

TEXTSIZE has no effect if the current text style has a fixed height.

 

-edit- if you just want the height to be 2.0, enter "2.0" instead of Height in your (command... ) line. Right now it is setting the value of Height to 2 times the current dimscale.

Share this post


Link to post
Share on other sites
Tharwat
(defun c:Test (/ str p)
 (if (and (not (eq (setq str (getstring t "\n Type text string :")) ""))
      (setq p (getpoint "\n Specify Text location :"))
     )
   (entmake (list '(0 . "MTEXT") '(100 . "AcDbEntity") '(100 . "AcDbMText")
          (cons 10 p)
          (cons 40 (* (getvar "DIMSCALE") 2.0))
          (cons 7 (if (tblsearch "STYLE" "My_Style")  "My_Style"   "Standard" ))
          (cons 1 str)
        )
   )
 )
 (princ)
)

Share this post


Link to post
Share on other sites
Arepo

What I am trying is to write a set of commands for different text styles and sizes. The text styles to be used are already loaded in the drawing template. Of course, text size should depend on DIMSCALE. I want the command to look as close to AutoCAD Mtext command as possible (have the Text Formatting box and the ability to write text on multiple lines). Something simple like MTEXT (MT) command I tried above, only having text style and text size predefined so I won't have to change them for different texts I'm using.

Rickh: The text styles I'm using don't have a predefined text height and I need text height depending on DIMSCALE so I have the right text size in Paper Space.

Tharwat: thank you for your code, works well but gives me the option to write text on one line only. Could you tell me why the code I tried doesn't work properly?

Share this post


Link to post
Share on other sites
Tharwat

Tharwat: thank you for your code, works well but gives me the option to write text on one line only.

 

Try this .... :)

 

(defun c:Test (/ lst st p)
 (while (not (eq (setq st (getstring t "\n Type text string :")) "")
        )
   (setq lst (cons (strcat st "\\P") lst))
 )
 (if (setq p (getpoint "\n Specify Text location :"))
   (entmake (list '(0 . "MTEXT")
                  '(100 . "AcDbEntity")
                  '(100 . "AcDbMText")
                  (cons 10 p)
                  (cons 40 (* (getvar "DIMSCALE") 2.0))
                  (cons 7
                        (if (tblsearch "STYLE" "My_Style")
                          "My_Style"
                          "Standard"
                        )
                  )
                  (cons 1 (apply 'strcat (reverse lst)))
            )
   )
 )
 (princ)
)

Share this post


Link to post
Share on other sites
Lee Mac

An alternative method:

 

(defun c:mtx ( / e h p s )

   (setq s "My_Style"
         h (* 2 (getvar 'dimscale))
   )    
   (if (setq p (getpoint "\nPoint for MText: "))
       (progn
           (setq e
               (entmakex
                   (list
                      '(0 . "MTEXT")
                      '(100 . "AcDbEntity")
                      '(100 . "AcDbMText")
                      '(1 . "")
                       (cons 10 (trans p 1 0))
                       (cons 40 h)
                       (cons 07 (if (tblsearch "STYLE" s) s "Standard"))
                   )
               )
           )
           (command "_.mtedit" e)
       )
   )
   (princ)
)

Share this post


Link to post
Share on other sites
Arepo
An alternative method:

 

That's exactly what I was looking for. I like having the Text Formatting window. It turned out to be more complicated code than I thought :)

Thank you very much!

Share this post


Link to post
Share on other sites
Lee Mac

You're very welcome Arepo :)

Share this post


Link to post
Share on other sites
Arepo

Thank you Tharwat, this works nicely.

Share this post


Link to post
Share on other sites
Tharwat
Thank you Tharwat, this works nicely.

 

No problem ..

Share this post


Link to post
Share on other sites
cwake

I have recently discovered by accident that the mtext editor command (as in mtedit) can be called as a function in LISP. Since I can't find this information mentioned anywhere else, I am posting it here purely in the interests of sharing the information with those who have an interest. I am not at this point suggesting that it be used instead of (command). :roll:

 

What I have discovered so far is that the function is defined in "acmted.arx", and that it is demand loaded when the command is invoked. Which means if you want to call it as a function you would need to check if it is loaded first. The function appears to be called with just the one variable, the ename of the MTEXT entity, as in

 

(mtedit ename)

 

I haven't nutted much else out yet, but it returns a symbol.

Share this post


Link to post
Share on other sites
Arepo

Lee Mac, I've been using the code you suggested for a while in my program and it worked fine as long as I'd been using World UCS. It does not work when I use a different UCS, the insertion point translates into world UCS, I guess and my picked point "p" jumps elsewhere. I know the culprit is "(cons 10 (trans p 1 0))" and I tried different ways to make it work, but unsuccessfully. Basically I'm trying to get some code that keeps the point where I pick it regardless of the UCS I use, because sometimes I have to change the UCS often. I would appreciate if you could suggest anything. Thank you!

Share this post


Link to post
Share on other sites
Lee Mac
Lee Mac, I've been using the code you suggested for a while in my program and it worked fine as long as I'd been using World UCS. It does not work when I use a different UCS, the insertion point translates into world UCS, I guess and my picked point "p" jumps elsewhere.

 

Please try the following instead:

(defun c:mtx ( / e h p s )

   (setq s "My_Style"
         h (* 2 (getvar 'dimscale))
   )    
   (if (setq p (getpoint "\nSpecify point for mtext: "))
       (if
           (setq e
               (entmakex
                   (list
                      '(000 . "MTEXT")
                      '(100 . "AcDbEntity")
                      '(100 . "AcDbMText")
                      '(001 . "")
                       (cons 010 (trans p 1 0))
                       (cons 011 (getvar 'ucsxdir))
                       (cons 040 h)
                       (cons 007 (if (tblsearch "style" s) s "Standard"))
                       (cons 210 (trans '(0 0 1) 1 0 t))
                   )
               )
           )
           (command "_.mtedit" e)
       )
   )
   (princ)
)

I'm pleased that you find this old program useful!

Share this post


Link to post
Share on other sites
Arepo

Thank you so much, Lee Mac, that fixes the problem. I've been using the program for years now.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×