Here's a real simple one I did, modeled after a thread here. It's nice because it allows me to have the last typed in input available for the next time I create a text object. It's real simple.
;;; Quick Text
;;; Required Subroutines: AT:Mtext AT:Getstring
;;; Alan J. Thompson, 09.23.09
(defun c:QT (/ #Point1 #Point2 #String #Text #Final)
(or QT:Default (setq QT:Default ""))
(and (setq #String (AT:Getstring "Specify text string: " QT:Default))
(not (eq #String ""))
(setq QT:Default (strcase #String))
(setq #Point1 (getpoint "\nSpecify placement point: "))
(or (setq
#Point2 (getpoint #Point1 "\nSpecify next point for angle <Zero>: ")
) ;_ setq
(setq #Point2 #Point1)
) ;_ or
(setq #Text (AT:Mtext #Point1 QT:Default 0 nil 5))
(not (vla-put-rotation #Text (angle #Point1 #Point2)))
(while (eq 5 (car (setq #Final (grread T 4 4))))
(vla-put-insertionpoint #Text (vlax-3d-point (trans (cadr #Final) 1 0)))
) ;_ while
) ;_ and
(princ)
) ;_ defun
You would need these two subroutines:
;;; Add MText to drawing
;;; #InsertionPoint - MText insertion point
;;; #String - String to place in created MText object
;;; #Width - Width of MText object (if nil, will be 0 width)
;;; #Layer - Layer to place Mtext object on (nil for current)
;;; #Justification - Justification # for Mtext object
;;; 1 or nil= TopLeft
;;; 2= TopCenter
;;; 3= TopRight
;;; 4= MiddleLeft
;;; 5= MiddleCenter
;;; 6= MiddleRight
;;; 7= BottomLeft
;;; 8= BottomCenter
;;; 9= BottomRight
;;; Alan J. Thompson, 05.23.09
(defun AT:MText (#InsertionPoint #String #Width #Layer #Justification / #Width
#Space #Insertion #Object
)
(or #Width (setq #Width 0))
(or *AcadDoc*
(setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object)))
) ;_ or
(setq #Space (if (or (eq acmodelspace
(vla-get-activespace *AcadDoc*)
) ;_ eq
(eq :vlax-true (vla-get-mspace *AcadDoc*))
) ;_ or
(vla-get-modelspace *AcadDoc*)
(vla-get-paperspace *AcadDoc*)
) ;_ if
#Insertion (cond
((vl-consp #InsertionPoint) (vlax-3d-point #InsertionPoint))
((eq (type #InsertionPoint) 'variant) #InsertionPoint)
(T nil)
) ;_ cond
) ;_ setq
;; create MText object
(setq #Object (vla-addmtext #Space #Insertion #Width #String))
;; change layer, if applicable
(and #Layer
(tblsearch "layer" #Layer)
(vla-put-layer #Object #Layer)
) ;_ and
;; change justification & match insertion point with new justification
(cond ((member #Justification (list 1 2 3 4 5 6 7 8 9))
(vla-put-attachmentpoint #Object #Justification)
(vla-move #Object
(vla-get-InsertionPoint #Object)
#Insertion
) ;_ vla-move
)
) ;_ cond
#Object
) ;_ defun
;;; Getstring Dialog Box
;;; #Title - Title of dialog box
;;; #Default - Default string within edit box
;;; Alan J. Thompson, 08.25.09
(defun AT:GetString
(#Title #Default / #FileName #FileOpen #DclID #NewString)
(setq #FileName (vl-filename-mktemp "" "" ".dcl")
#FileOpen (open #FileName "W")
) ;_ setq
(foreach x '("TempEditBox : dialog {" "key = \"Title\";"
"label = \"\";" "initial_focus = \"Edit\";" "spacer;"
": row {" ": column {" "alignment = centered;"
"fixed_width = true;" ": text {" "label = \"\";" "}" "}"
": edit_box {" "key = \"Edit\";" "allow_accept = true;"
"edit_width = 40;" "fixed_width = true;" "}" "}"
"spacer;" ": row {" "fixed_width = true;"
"alignment = centered;" ": ok_button {" "width = 11;" "}"
": cancel_button {" "width = 11;" "}" "}" "}//"
)
(write-line x #FileOpen)
) ;_ foreach
(close #FileOpen)
(setq #DclID (load_dialog #FileName))
(new_dialog "TempEditBox" #DclID)
(set_tile "Title" #Title)
(set_tile "Edit" #Default)
(action_tile
"accept"
"(setq #NewString (get_tile \"Edit\"))(done_dialog)"
) ;_ action_tile
(action_tile "cancel" "(done_dialog)")
(start_dialog)
(unload_dialog #DclID)
(vl-file-delete #FileName)
#NewString
) ;_ defun