Message 1 of 6
Rotate Text to line and keep in position
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All,
For the last decade I have been using a lisp to rotate text to match the angle of line but the text is kept in position (the next is not moved to a offset to the line).
Unfortunately with the last couple of version of Autocad 2022 – 2024 we have found the lisp has become unreliable. Selecting the text works fine but selecting the line can generate the error
Select point on object to label.; error: bad argument type: numberp: nil
It can be hit and miss when the error will occur. Sometime trying the same thing will work on the third go.
Does anyone have another lisp that would rotate text in place by selectign the a line? Or possibly the time to review the one below. The original lisp was found here. https://www.cadtutor.net/forum/topic/560-rotate-text-to-align-line/#comment-4179
Many thanks
;; Text Rotated to the selected object angle
(defun c:TRA() (c:TextRotate2Angle))
(defun c:TextRotate2Angle (/ ss lst pt ang obj
get_pt_and_angle )
(vl-load-com)
;; User selection of curve object
;; return pick point & average angle of curve at pick point
(defun get_pt_and_angle (prmpt / ent p@pt parA parB pt ang)
(if (and (setq ent (entsel prmpt))
(not (vl-catch-all-error-p
(setq pt (vl-catch-all-apply
'vlax-curve-getClosestPointTo
(list (car ent) (cadr ent))
)
)
)
)
)
(progn
(setq ent (car ent)
p@pt (vlax-curve-getParamAtPoint ent pt)
parA (max 0.0 (- p@pt 0.05))
parB (min (+ p@pt 0.05) (vlax-curve-getEndParam ent))
ang (angle (vlax-curve-getPointAtParam ent parA)
(vlax-curve-getPointAtParam ent ParB)
)
)
(list pt ang)
)
)
)
;; Get Text to align & object to alignment angle
;; Text is not moved, just rotated to the alignment angle
;; Object must have curve data
(prompt "\nSelect text object to align.")
(if (and (or (setq ss (ssget "_+.:E:S" '((0 . "Text,Mtext"))))
(prompt "\n** No Text object selected. **"))
(or (setq lst (get_pt_and_angle "\nSelect point on object to label."))
(prompt "\n** Missed or no curve data for object."))
)
(progn
(setq pt (car lst)
;; ang (FixTextAngle (cadr lst))
ang (cadr lst)
obj (vlax-ename->vla-object (ssname ss 0))
)
(vla-put-rotation Obj ang)
)
)
(princ)
)