Author Topic: MTEXT in LISP?  (Read 14170 times)

0 Members and 1 Guest are viewing this topic.

Darryl

  • Guest
MTEXT in LISP?
« on: July 26, 2004, 03:22:55 PM »
How can I use LISP to place some MTEXT in a drawing?
I've tried this, but it don't work:

Code: [Select]
(command "-MTEXT" pt1 pt2 "My text here" "")

Thanks in advance!
Darryl

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
MTEXT in LISP?
« Reply #1 on: July 26, 2004, 03:58:54 PM »
If no one else answers this by morning I'll give you full breakdown then, gotta go ..........
TheSwamp.org  (serving the CAD community since 2003)

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
MTEXT in LISP?
« Reply #2 on: July 27, 2004, 06:51:20 AM »
I tried the same exact procedure as you and it works like a champ.
Code: [Select]

Command: (setq p1 (getpoint))
(5.63372 7.9623 0.0)

Command: (setq p2 (getcorner p1))
(8.4186 6.30984 0.0)

Command: (command "_mtext" p1 p2 "this is some text" "")
_mtext Current text style:  "Standard"  Text height:  0.1800
Specify first corner:
Specify opposite corner or [Height/Justify/Line spacing/Rotation/Style/Width]:
MText: this is some text
MText:


Are you getting any errors messages?
Do you have  cmdecho turned on? (set to 1)

What happens when you run the following:
Code: [Select]

(defun c:MyMtext (/ p1 p2 txt)
  (setq p1 (getpoint "\nSelect top left corner: ")
        p2 (getcorner p1 "\nSelect bottom rigth corner: ")
txt (getstring T "\nEnter some text: ")
)

  (command "_.mtext" p1 p2 txt "")

  )
TheSwamp.org  (serving the CAD community since 2003)

daron

  • Guest
MTEXT in LISP?
« Reply #3 on: July 27, 2004, 08:12:51 AM »
Mark, you're using an underscore. In Daryl's procedure, he used a hyphen. Could this be the difference?

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
MTEXT in LISP?
« Reply #4 on: July 27, 2004, 08:49:27 AM »
Quote from: Daron
Mark, you're using an underscore. In Daryl's procedure, he used a hyphen. Could this be the difference?

I don't think so, I tried it both ways with the same results.
TheSwamp.org  (serving the CAD community since 2003)

sinc

  • Guest
MTEXT in LISP?
« Reply #5 on: July 27, 2004, 08:50:56 AM »
Yes indeed.  This appears to be another instance of AutoCAD setting up the same thing in two different ways, depending on what you're doing, just to increase confusion...  :)

Hypens are used in command ALIASES to indicate that the command line (or default) version of the command should be used, even if the command has been redefined by the user.  The corresponding item in VLISP (and menus) is a period (".").  Therefore, to accomplish the same thing as "-mtext" for an alias, you need to use ".mtext" in Lisp.

The underscore is something else, used for internationalization - i.e., users who speak a language other than English.  It tells AutoCAD to check the user's language setting, and run the command using prompts in the user's language.  You can write your own routines to do this, too, but it's more work, so people generally only do it if they plan on marketing and selling their code.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
MTEXT in LISP?
« Reply #6 on: July 27, 2004, 09:23:12 AM »
All of these worked for me in ACAD 2000, although I have trouble with the last
example not returning to the lisp.
Mtext needs the ( initdia ) if you want to force the dialog box so the minus sign
is not needed. The ._ is recommended or language & command redirections override.
The width can be set to zero so you don't have to pick the second corner. In
that case the width is determined by hitting carriage return at the end of each
line of text.

If you want to build a mtext object with more than 254 characters see this:
http://theswamp.org/phpBB2/viewtopic.php?t=949&highlight=mtext+width

Code: [Select]
(defun c:MyMtext (/ p1 p2 txt)
  (command "mtext" pause "w" "0" ) ; get LL corner
  (princ)
) ; exit and wait for user to enter test


(defun c:MyMtext (/ p1 p2 txt)
  (setq p1  (getpoint "\nSelect top left corner: ")
        txt (getstring T "\nEnter some text: ")
  )
  (command "-mtext" p1 "w" "0" txt "" )
  (princ)
)

(defun c:MyMtext (/ p1 p2 txt)
  (setq p1  (getpoint "\nSelect top left corner: ")
        p2  (getcorner p1 "\nSelect bottom rigth corner: ")
        txt (getstring T "\nEnter some text: ")
  )
  (command "mtext" p1 p2 txt "" )
  (princ)
)

(defun c:MyMtext (/ p1 p2 txt)
  (setq p1  (getpoint "\nSelect top left corner: ")
        txt (getstring T "\nEnter some text: ")
  )
  (command "mtext" p1 "w" "0" txt "" )
  (princ)
)


(defun c:MyMtext (/ p1 p2 txt)
  (setq p1  (getpoint "\nSelect top left corner: ")
        p2  (getcorner p1 "\nSelect bottom rigth corner: ")
  )
  (initdia)
  (command "mtext" p1 p2 pause "")
  ;;  ACAD pauses here for uset click ???
  (command)
  (command)
  (print "test is over")
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Darryl

  • Guest
MTEXT in LISP?
« Reply #7 on: July 27, 2004, 09:34:13 AM »
Hi guys,
After reading Mark's response this morning, I tried it again, and... :oops:  it worked for me too.

I don't know what my problem was yesterday.  I didn't get an error message, but the command line was always waiting for my MTEXT string.

I also noted the difference between my dash and Mark's underscore, and both work for me too.  I used the dash so that MTEXT wouldn't bring up the dialog box - thought it was necessary, but I guess not in this case.  Thanks Sinc for the explanation on punctuation.

One more little detail:  I have a couple words in my MTEXT string that I want underlined, but %%u doesn't work here.  Is there a way to do it?

And, Mark, thanks for the great forum!  I'd always used CADalog.com and was disappointed when it went down recently.  But Mike Williams steered me in the right direction - to theSwamp.org!   :D

Anonymous

  • Guest
MTEXT in LISP?
« Reply #8 on: July 27, 2004, 09:44:33 AM »
command line MTEXT always got error, use entmake to create MTEXT directly via LISP

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
MTEXT in LISP?
« Reply #9 on: July 27, 2004, 10:34:43 AM »
See the link in my post for more on entmake mtext.
For underline use the following code.
For more formatting codes look in VLIDE HELP under 'mtext object" "Formatting codes"
I don't think all the codes are displayed there. :)
Code: [Select]
(defun c:mymtext (/ p1 p2 txt)
  (setq p1  (getpoint "\nSelect top left corner: ")
        p2  (getcorner p1 "\nSelect bottom rigth corner: ")
        txt "This is a test string with some \\Lundeline\\l in it."
  )
  (make_mtext p1 p2 txt)
  (princ)
)


(defun make_mtext (p1 p2 txt / txt_ht width)
  (setq txt_ht 5
        width  (abs(- (car p2) (car p1)))
  )

  (entmake
    (list
      '(0 . "MTEXT")
      '(100 . "AcDbEntity")
      '(100 . "AcDbMText")
      (cons 10 p1)
      (cons 7 (getvar "TextStyle")) ; Current Style
      (cons 40 txt_ht) ; (getvar "TextSize")) ; Current height
      (cons 41 width) ; 0 Width = no wrap
      (cons 71 1) ; 1 = Top Left
      (cons 50 0.0) ; rotation angle
      (cons 1 txt)
    )
  )
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.