I have a routine the requires selection of a single text entity. Getting custom prompts to work correctly in both Autocad and Bricscad with the native commands has not been going well, and ssget only recognizes the outline of each character.
This function allows for custom prompts and does rollover highlighting of text entities based on the the aligned bounding box for the text entity.
(defun c:select_text (/ dim_scale half_pi loop new_entity old_entity
ret_val two_pi
)
(defun get_text (cursor_point offset_distance filter / angle1 angle2 ; gets text using a bounding box
base_angle base_point box entity LL point1 point2
selset text_ename text_height UR
)
(defun delta (a1 a2 / r1) ; gets the absolute angle between two vectors
(cond ((> a1 (+ a2 pi)) (setq a2 (+ a2 two_pi))) ; based on code by John Uhden
((> a2 (+ a1 pi)) (setq a1 (+ a1 two_pi)))
)
(setq r1 (- a2 a1))
(if (< r1 0.0)
(setq r1 (+ r1 two_pi))
)
r1
)
(if (vl-string-search "BRICSCAD" (strcase (getvar "acadver"))) ; Bricscad does not like really small selection windows
(if (< offset_distance 0.001) (setq offset_distance 0.001))
)
(setq selset (ssget "c" ; get the text entities at the cursor
(list (- (car cursor_point) offset_distance) (- (cadr cursor_point) offset_distance))
(list (+ (car cursor_point) offset_distance) (+ (cadr cursor_point) offset_distance))
filter
)
)
(setq counter 0
text_ename nil
)
(if selset
(progn
(setq entity (entget (ssname selset 0)) ; just look at first entity
text_height (cdr (assoc 40 entity))
base_angle (cdr (assoc 50 entity))
base_point (cdr (assoc 10 entity))
box (textbox entity) ; get the normalized containing box
point1 (car box) ; normalized LL point
point2 (cadr box) ; normalized UR point
LL (polar (trans (cdr (assoc 10 entity)) 0 1) ; actual LL point
(+ (angle '(0 0) point1) base_angle)
(distance '(0 0) point1)
)
UR (polar LL ; actual UR point
(+ base_angle (angle point1 point2))
(distance point1 point2)
)
angle1 (delta base_angle (angle LL cursor_point)) ; angle from LL to cursor
angle2 (delta base_angle (angle UR cursor_point)) ; from UL to cursor
)
(if (and (>= angle1 0.0) ; test if the cursor is in the included
(<= angle1 half_pi) ; angle at the LL and UL
(>= angle2 pi)
(<= angle2 (+ pi half_pi))
)
(setq text_ename (cdr (assoc -1 entity))) ; return the text's ename
)
(setq counter (1+ counter))
)
)
text_ename
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq old_entity nil
new_entity nil
loop T
dim_scale (getvar "dimscale")
)
(setq half_pi (* PI 0.5)
two_pi (* PI 2.0)
)
(princ "\rSelect text: ")
(while loop
(setq ret_val (car (setq gr_data (grread t 15 2))))
(cond ((= ret_val 5)
(setq new_entity (get_text (cadr gr_data) (* dim_scale 0.05) '((0 . "TEXT"))))
; get text entities at the cursor
(if (/= new_entity old_entity) ; the entity has changed...
(if new_entity ; if the new entity is not nil...
(redraw new_entity 3) ; highlight the new entity
(if old_entity
(redraw old_entity 4) ; unhighlight the old entity
)
)
)
(setq old_entity new_entity) ; store the last entity
)
((= ret_val 3)
(setq loop nil)
)
)
)
(if new_entity ; if the new entity is not nil...
(redraw new_entity 4) ; highlight the new entity
)
(print new_entity) ; return the entity's ename
(princ)
)