(defun textinline (txt / entt txt ent pkpt entinf enttyp rot txtnam)
(SETUP)
(lrs "G-ANNO-TEXT")
(SETVAR "OSMODE" 0)
(setvar "texteval" 1)
(if (= nil txt)
(setq txt (getstring T "\n(Press 'Esc' to cancel) Enter Label: ")))
(while (setq ent (entsel "\n(Press 'Esc' to cancel) What do you want to label?"))
(setq pkpt (osnap (cadr ent) "nea"))
(setq entt (car ent))
(setq entinf (entget entt))
(setq enttyp (cdr (assoc 0 entinf)))
(cond
((member enttyp '("LINE" "LWPOLYLINE"))
(setq rotpt (osnap pkpt "end"))
)
((member enttyp '("ARC" "CIRCLE"))
(setq rotpt (osnap pkpt "cen"))
)
(T (ALERT "Must Select ARC CIRCLE POLYLINE or LINE"))
)
(setq rot (angle pkpt rotpt))
(if (and (<= rot (* 3 (/ pi 2))) (> rot (/ pi 2)))
(setq rot (+ rot pi))
)
(if (equal rot (* 3 (/ pi 2)) 0.01)
(setq rot (/ pi 2))
)
(command "text" "j" "m" pkpt "" (* rot (/ 180 pi)) txt)
(setq txtnm (entlast))
(cond
((member enttyp '("ARC" "CIRCLE"))
(command "rotate" txtnm "" pkpt 90)
)
(T)
)
(setq ed (entget txtnm))
(setq rot (cdr (assoc 50 (entget txtnm))))
(entmod ed)
(entupd txtnm)
(command "trim" txtnm "" ent "")
)
(END)
(C:textinline)
)
(defun c:textinline()
(textinline nil)
)
Command: textinline
Command: (Press 'Esc' to cancel) Enter Label: HWC
What do you want to label?Unknown command "HWC". Press F1 for help.
(DEFUN textinline (txt / entt txt ent pkpt entinf enttyp rot txtnam)
;;; do stuff
(c:textinline)
)
(DEFUN c:textinline () (textinline nil))
(COND ((MEMBER enttyp '("LINE" "LWPOLYLINE"))
(SETQ rotpt (OSNAP pkpt "end"))
)
((MEMBER enttyp '("ARC" "CIRCLE")) (SETQ rotpt (OSNAP pkpt "cen")))
(T (ALERT "Must Select ARC CIRCLE POLYLINE or LINE"))
)
What do you expect to happen if/after this conditional gets to the alert message
(DEFUN c:textinline () (textinline nil))
(DEFUN textinline (textstring /
etype selectedent
selectionpoint textstring
;;
*error* _dtr
_rtd _stringprintable-p
_drawtext _settextangle
_trimfortext _textincircle
_textinline
)
;;
;;-----------------------------------------
;; kwb@theSwamp 20060819
;; proof of concept code for
;; http://www.theswamp.org/index.php?topic=11903.msg148247#msg148247
;;-----------------------------------------
;;
;; (setup)
;; (lrs "G-ANNO-TEXT")
;;
;; The previous values SHOULD be saved and restored later.
(SETVAR "OSMODE" 0)
(SETVAR "texteval" 1)
;;
;;-----------------------------------------
(DEFUN *error* (errormessage /)
(COND ((NOT errormessage)) ; no error, do nothing
((VL-POSITION (STRCASE errormessage T) ; cancel
'("console break"
"function cancelled"
"quit / exit abort"
)
)
)
((PRINC (STRCAT "\nApplication Error: "
(GETVAR "errno")
" :- "
errormessage
)
)
)
)
;; (VL-BT)
;;(end)
)
;;-----------------------------------------
(DEFUN _dtr (ang) (* PI (/ ang 180.0)))
;;-----------------------------------------
(DEFUN _rtd (ang) (/ (* ang 180.0) PI))
;;-----------------------------------------
(DEFUN _stringprintable-p (arg)
(AND (= (TYPE arg) 'str)
(/= 0 (STRLEN arg))
(/= 0 (STRLEN (VL-STRING-TRIM " " arg)))
)
)
;;-----------------------------------------
(DEFUN _settextangle (ang)
(IF (AND (> ang (_dtr 105)) (<= ang (_dtr 285)))
(- ang PI)
ang
)
)
;;-----------------------------------------
(DEFUN _drawtext (selectionpoint rotationangle /)
(COMMAND "text"
"j"
"m"
selectionpoint
""
(_rtd (_settextangle rotationangle))
textstring
)
(ENTLAST)
)
;;-----------------------------------------
(DEFUN _textinline (selectedent selectionpoint / textent)
(IF (SETQ textent (_drawtext
selectionpoint
(ANGLE selectionpoint
(OSNAP selectionpoint "end")
)
)
)
(_trimfortext textent selectedent)
)
)
;;-----------------------------------------
(DEFUN _textincircle
(selectedent selectionpoint / textent)
(IF (SETQ
textent (_drawtext
selectionpoint
(+ (ANGLE (OSNAP selectionpoint "cen")
selectionpoint
)
(* PI 0.5)
)
)
)
(_trimfortext textent selectedent)
)
)
;;-----------------------------------------
(DEFUN _trimfortext (textent selectedent /)
(COMMAND "trim" textent "" selectedent "")
)
;;-----------------------------------------
;;
;; Main ...
;;
(WHILE (NOT (_stringprintable-p textstring))
(SETQ textstring
(GETSTRING
T
"\n(Press 'Esc' to cancel) Enter Label: "
)
)
)
(WHILE (SETQ selectedent
(ENTSEL
"\n(Press 'Esc' to cancel) What do you want to label?"
)
)
;;
(SETQ selectionpoint (OSNAP (CADR selectedent) "nea")
etype (CDR (ASSOC 0 (ENTGET (CAR selectedent))))
)
(COND ((MEMBER etype '("LINE" "LWPOLYLINE"))
(_textinline selectedent selectionpoint)
)
((MEMBER etype '("ARC" "CIRCLE"))
(_textincircle selectedent selectionpoint)
)
(T
(ALERT "Must Select ARC CIRCLE POLYLINE or LINE")
)
)
)
;;-----------------------------------------
;; (end)
(PRINC)
)
(PROMPT "\n command-line >> TextInline ")
(PRINC)
(defun _DrawText ( selectionPoint rotationAngle / elast result )
;; If it were me I would make the (lexical) global
;; variable 'textstring' an argument of the _DrawText
;; function but I wanted to honour the function's
;; signature as you had originally penned, lest calling
;; code get a rake in the face. An aside, I'd make the
;; text via entmake or vla-addtext but that's another
;; story. Anyway ...
(setq elast (entlast))
(apply 'command
(append
(list ".text" "_j" "_m" selectionPoint)
(if
(zerop
(cdr
(assoc 40
(tblsearch "style"
(getvar "textstyle")
)
)
)
;; the activex route to same if you're
;; interested --
;;
;; (vla-get-height
;; (vla-get-activetextstyle
;; (vla-get-activedocument
;; (vlax-get-acad-object)
;; )
;; )
;; )
)
;; we could use a space / carriage
;; return but let's be explicit
(list (getvar "textsize"))
)
(list rotationAngle textstring)
)
)
;; Caller should deal with a null result, which
;; indicates the text entity was not created for
;; some reason.
(if (/= elast (setq result (entlast)))
result
)
)
Command: text
Current text style: "NORMAL" Text height: 50.00
Specify start point of text or [Justify/Style]: j
Enter an option [Align/Fit/Center/Middle/Right/TL/TC/TR/ML/MC/MR/BL/BC/BR]: m
Specify middle point of text:
Specify height <35.00>:
Specify rotation angle of text <0.000>:
Command: textstyle
Enter new value for TEXTSTYLE <"NORMAL">: T35
Command: text
Current text style: "T35" Text height: 35.00
Specify start point of text or [Justify/Style]: j
Enter an option [Align/Fit/Center/Middle/Right/TL/TC/TR/ML/MC/MR/BL/BC/BR]: m
Specify middle point of text:
Specify rotation angle of text <0.000>:
;;-----------------------------------------
(DEFUN _drawtext (selectionpoint rotationangle /)
(COMMAND "text"
"Style"
"MySuperDuperTextStyleWithZeroHeight"
"j"
"m"
selectionpoint
""
(_rtd (_settextangle rotationangle))
textstring
)
(ENTLAST)
)
;;-----------------------------------------
;;-----------------------------------------
(DEFUN _drawtext (selectionpoint rotationangle /)
(COMMAND "text"
"Style"
"MySuperDuperTextStyleWithFixedHeight"
"j"
"m"
selectionpoint
;; "" <-- not needed in this case
(_rtd (_settextangle rotationangle))
textstring
)
(ENTLAST)
)
;;-----------------------------------------
I won't be around later so I don't want to leave you twistin' in the wind, here's one possible remedy :replace the _DrawText function in previous posts with the following (no offence to the fine work of prior posters is this thread) --
I didn't test the program greater so I don't know if it will actually remedy all the ills. Like I inferred earlier, it's just what lept off the page at me.
Works flawlessly Kerry & MP many thanks!
Do you guys have any AutoLISP books published?
(DEFUN _drawtext (selectionpoint rotationangle /)
(COMMAND "text"
"j"
"m"
selectionpoint
""
(_rtd (_settextangle rotationangle))
textstring
)
(ENTLAST)
)
(DEFUN _DrawText (selectionPoint rotationAngle / elast result)
(setq elast (entlast))
(apply 'command
(append
(list ".text" "_j" "_m" selectionPoint)
(if
(zerop
(cdr
(assoc 40
(tblsearch "style"
(getvar "textstyle")
)
)
)
)
(list (getvar "textsize"))
)
(list rotationAngle textstring)
)
)
;; Caller should deal with a null result, which
;; indicates the text entity was not created for
;; some reason.
(if (/= elast (setq result (entlast)))
result
)
)
....
MP'sCode: [Select](DEFUN _drawtext (selectionpoint rotationangle /)
;;..
Your DrawText:Code: [Select](DEFUN _DrawText (selectionPoint rotationAngle / elast result)
;;...
are you converting the radians to degrees ??
(DEFUN _DrawText (selectionPoint rotationAngle / elast result)
(setq elast (entlast))
(apply 'command
(append
(list ".text" "_j" "_m" selectionPoint) ;; begins the sequence
(if (zerop (cdr (assoc 40 (tblsearch "style" (getvar "textstyle"))))) ;; from here this is checking the text height for zero?
(list (getvar "textsize"))
)
(list rotationAngle textstring)
)
)
(if (/= elast (setq result (entlast))) result)
(ENTLAST)
)
I'm running out of gas here. I'll pick up in the morning and see if I can get this through my knot head
Just a note.
Some of us sometimes ask question to help with responding to the original or subsequent posts. If you dont understand the questions, please say so, 'cause usually a solution depends on your answers.
(defun _drawtext (txt txtjust txtpt txtang)
;; If text height is undefined (signified by 0 in the table)
(if (= (cdr (assoc 40 (tblsearch "style" (getvar "textstyle")))) 0)
;; Draw the text using the current text height (textsize)
(command "._text" "_J" txtjust txtpt "" txtang txt)
;; Otherwise use the defined text height
(command "._text" "_J" txtjust txtpt txtang txt)
) ; endif
)
(defun c:test ()
(defun rtd (r) (* 180.0 (/ r pi)))
(and
(setq mytext (getstring t "\nEnter text: "))
(setq textpoint (getpoint "\nSelect text point."))
(setq textangle (rtd 0.785398)) ; 45 degrees
(_drawtext mytext "_m" textpoint textangle)
)
(princ)
)