Author Topic: Using MTEXT within a program  (Read 3435 times)

0 Members and 1 Guest are viewing this topic.

Craig

  • Guest
Using MTEXT within a program
« on: May 11, 2005, 05:09:17 PM »
Anyone know of a way to incorporate MTEXT into a lisp program? Basically we are creating custom leaders and afterwards want to place MTEXT at the end of the leader line. Somethin like so
Code: [Select]
(setq mecTextLocation (list (+ (car mecPt3) 4) (cadr mecPt3)))
(command "-mtext" mecTextLocation "j" "ml" "w" "" TYPE IN TEXT HERE)

but this does not work since TYPE IN TEXT HERE is the problem and I can't use PAUSE for user input which causes a NIL and if there are any lines after this line it tries to insert it. Any ideas? I know I can add text at the end of it and calculate the height and add new lines for that but I really didn't want to do that.

CADaver

  • Guest
Using MTEXT within a program
« Reply #1 on: May 11, 2005, 05:16:56 PM »
Use (setq stufff (getstring.... to get the string first.
the following code gets the first insertion point and the string first, then adds a big NOTE to the front of that. then it enters the MTEXT command. notice it sets the paragraph width to 2 times the dimscale.

Code: [Select]
(defun c:NOTE ()
(setq
  pt1 (getpoint "\n Specify Top-Left corner: ")
  newtext (getstring T "\n Enter NOTE Text: ")
)
(setq notetxt (strcase (strcat "\{\\L\\W1\\H1.25X\\FROMAND;_NOTE_\}:\\P" newtext)))  
(command ".mtext" pt1 "j" "tl" "w" (* 2.0 (getvar "dimscale")) notetxt "")
)

Craig

  • Guest
Using MTEXT within a program
« Reply #2 on: May 11, 2005, 05:25:30 PM »
Well the problem with that is we will be entering multiple lines of text. Getstring doesn't offer but one line once you hit enter. This is why we need to use MTEXT or even invoke the DTEXT command.

CADaver

  • Guest
Using MTEXT within a program
« Reply #3 on: May 11, 2005, 05:40:31 PM »
Quote from: Craig
Well the problem with that is we will be entering multiple lines of text. Getstring doesn't offer but one line once you hit enter. This is why we need to use MTEXT or even invoke the DTEXT command.
with mtext there is no need to hit enter more than once.  just keyin the entire string and let it word wrap, word wrapping is the whole idea behind mtext.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Using MTEXT within a program
« Reply #4 on: May 11, 2005, 08:05:39 PM »
Here is a sub routine that will take a text string as an argument, open the mtext dialog
and return the edited text. You can then create the mtext object with your specifications.

Code: [Select]
;;; FUNCTION
;;;   Use ddedit box to edit a text string.
;;;
;;; ARGUMENTS
;;;  txt = the text string
;;;
;;; USAGE
;;;  mtext_edit
;;;
;;; PLATFORMS
;;; 2000+
;;;
;;; AUTHOR
;;; Charles Alan Butler
;;; ab2draft@TampaBay.rr.com
;;;
;;; VERSION
;;; 1.0 May. 11, 2005 (defun mtext_edit (txt / entlist ent)
  (if (entmake (list
  '(0 . "MTEXT")
  '(100 . "AcDbEntity")
  '(100 . "AcDbMText")
  (cons 10 '(0 0 0)) ; insert point
  (cons 7 (getvar "TextStyle")) ; Current Style
  (cons 40 (getvar "TextSize")) ; Current height
  (cons 41 0)  ; 0 Width = no wrap
  (cons 71 1)  ; 1=Top Left Attachment point
                   (cons 1 txt) ; Text String
)
        )
    (progn
      (setq ent (entlast))
      (command "._ddedit" ent "")
      (setq txt (cdr (assoc 1 (entget ent))))
      (entdel ent)
      txt
    )
  )
)

(defun c:test(/ newtext)
  (setq newtext (mtext_edit "This is a test string."))
)


And here is the dtext version.

Code: [Select]
;;; FUNCTION
;;;   Use ddedit box to edit a text string.
;;;
;;; ARGUMENTS
;;;  txt = the text string
;;;
;;; USAGE
;;;  text_edit
;;;
;;; PLATFORMS
;;; 2000+
;;;
;;; AUTHOR
;;; Charles Alan Butler
;;; ab2draft@TampaBay.rr.com
;;;
;;; VERSION
;;; 1.0 Oct. 06, 2004
(defun text_edit (txt / entlist ent)
  (if (entmake
        (list
          '(0 . "TEXT")
          (cons 10 '(0 0))
          (cons 40 1)
          (cons 7 (getvar "TEXTSTYLE"))
          (cons 1 txt) ; Text String
        )
      )
    (progn
      (setq ent (entlast))
      (command "._ddedit" ent "")
      (setq txt (cdr (assoc 1 (entget ent))))
      (entdel ent)
      txt
    )
  )
)

(defun c:test(/ newtext)
  (setq newtext (text_edit "This is a test string."))
)
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.

Craig

  • Guest
Using MTEXT within a program
« Reply #5 on: May 12, 2005, 08:44:53 AM »
Quote from: CADaver
with mtext there is no need to hit enter more than once.  just keyin the entire string and let it word wrap, word wrapping is the whole idea behind mtext.


On many of the notes we can't let it word wrap. Each line is specific  as such
Line 1 - Description
Line 2 - Cat. #
Line 3 - Installation
Line 4 - Size
etc

Thats why word wrap won't work

CADaver

  • Guest
Using MTEXT within a program
« Reply #6 on: May 12, 2005, 09:00:52 AM »
Quote from: Craig
Quote from: CADaver
with mtext there is no need to hit enter more than once.  just keyin the entire string and let it word wrap, word wrapping is the whole idea behind mtext.


On many of the notes we can't let it word wrap. Each line is specific  as such
Line 1 - Description
Line 2 - Cat. #
Line 3 - Installation
Line 4 - Size
etc

Thats why word wrap won't work
ahh, see for us that kind of data would be attributes so we could extract the data for use elsewhere.

So hard code and line return using \P

    description\Pcatalog number\Pinstallation\Psize\P[/list:u]

Craig

  • Guest
Using MTEXT within a program
« Reply #7 on: May 12, 2005, 09:05:38 AM »
Thank you Charles, your program sparked my mind...what little of it's left. I inserted a symbol we use on all of our notes and then at the end did a ddedit on that symbol and it brings up the MTEXT box and does exactly what we needed. Thanks man!

Craig

  • Guest
Using MTEXT within a program
« Reply #8 on: May 12, 2005, 09:08:30 AM »
I see whatcha mean Randy, but we are using Building Systems and the things we are calling out are already inserted into a database through the software eliminating the need to do what you are doing. Building Systems is a rather remarkable add-on to AutoCAD.

CADaver

  • Guest
Using MTEXT within a program
« Reply #9 on: May 12, 2005, 10:54:42 AM »
Mr. Butler, sir, be the man... again, dood.

I haven't used building systems, but i've seen it.  doesn't it have a component labling function that would add this kind of dtat to the drawing?

Craig

  • Guest
Using MTEXT within a program
« Reply #10 on: May 12, 2005, 11:41:51 AM »
I don't know all the ins and outs of it yet. I've been at this company going on 3 weeks so I am going in July to Orlando, Fla. for 4 days of Autodesk Building Systems training. It's such an intense program I would probably never know all the things it offers without some form of training.