Something to play with ...
For my test ( Metric drawing )
Dimscale was 10
Expected Text location was 10,10,0 at 1:1 scale, so actually at 100,100,0 in the test drawing.
Proximity was 5 at 1:1, so actually 50 in the test drawing.
The routine determined that there were 3 text entities within a legal proximity to the nominated point
and highlighted the closest.
[color=green];; closest_text_to_nominatedpoint.lsp[/color]
[color=green];; Proof of concept Code : kdub@theSwamp 2010.10.01
;; http://www.theswamp.org/index.php?topic=35119.0
;; Select the closest TEXT to a nominated location
;; within a prescribed proximity.
;; The location and Proximity shall be factored by the Dimscale value.
;; [/color]
(defun [color=blue]c:Doit[/color] (/ [color=blue]_Select[/color] Location Halfboxsize
Halfboxsize Location Nearest_Obj Objlist
Proximitylist Scalefactor Scalematrix Sc_Halfbox
Sc_Loc Selectbox_Ll Selectbox_Ur Ss
)
(vl-load-com)
[color=green];; CodeHimBelonga kdub@theSwamp 2010.10.01
;; User Defined variables
;; .... values in Metric units.
;; these variables will be factored by DIMSCALE
;;[/color]
(setq location (list 10. 10. 0.0)
HalfBoxSize 5
)
[color=green];;--------------------------------------------------------------- [/color]
(defun [color=blue]_Select[/color] (/ result)
(setq ScaleFactor (getvar [color=Maroon]"DIMSCALE"[/color])
ScaleMatrix (list ScaleFactor ScaleFactor ScaleFactor)
)
[color=green];;[/color]
(setq sc_loc (mapcar '* ScaleMatrix location)
sc_halfBox (mapcar '* ScaleMatrix (list HalfBoxSize HalfBoxSize 0.0))
selectBox_ll (mapcar '- sc_loc sc_halfBox)
selectBox_ur (mapcar '+ sc_loc sc_halfBox)
)
[color=green];;[/color]
(if (setq ss (ssget [color=Maroon]"C"[/color] selectBox_ll selectBox_ur '((0 . [color=Maroon]"TEXT"[/color]))))
(setq result (mapcar 'vlax-ename->vla-object
(vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
)
)
[color=green];;[/color]
(alert [color=Maroon]"Ooooops"[/color])
)
result
)
[color=green];;---------------------------------------------------------------
;; Main Entry Point[/color]
(if (setq objList (_Select))
(progn (setq ProximityList '())
(foreach item objList
(setq ProximityList
(append
ProximityList
(list
([color=blue]Kdub:Vec:Calculatelength[/color]
(mapcar '- (vlax-get item 'InsertionPoint) sc_loc)
)
)
)
)
)
(setq nearest_Obj
(nth (vl-position (apply 'MIN ProximityList) ProximityList)
objList
)
)
)
(setq nearest_Obj nil)
)
(if nearest_Obj
(progn (vla-Highlight nearest_Obj :vlax-true)
(prompt [color=Maroon]"\nText is Highlighted"[/color])
)
(prompt [color=Maroon]"\nNo Text at nominated location"[/color])
)
(princ)
)
[color=green];;;-------------------------------------------------------------
;;;-------------------------------------------------------------
;;
;;; -- Function Kdub:Vec:Calculatelength
;;; Calculates length of a vector.
;;; Arguments [Type]:
;;; Vec = Vector [LIST]
;;; Return [Type]:
;;; > Length of the vector [REAL]
;;; Notes:
;;; None
;;[/color]
(defun [color=blue]Kdub:Vec:Calculatelength[/color] (Vector)
(car ([color=blue]kdub:vec:zeroaxisfuzz[/color]
(list (sqrt (apply '+ (mapcar '(lambda (a) (* a a)) Vector))))
)
)
)
[color=green];;
;;;-------------------------------------------------------------
;;;-------------------------------------------------------------
;;
;;; -- Function Kdub:Vec:Zeroaxisfuzz
;;; Recursively eliminates floating point precision problems when values are
;;; aproximately 0.
;;; Arguments [Type]:
;;; Lst = List or nestedlList of floating point numbers [LIST]
;;; Return [Type]:
;;; > Corrected list [LIST]
;;; Notes:
;;; None
;;[/color]
(defun [color=blue]Kdub:Vec:Zeroaxisfuzz[/color] (VectorList)
(mapcar '(lambda (a)
(if (= 'list (type a))
([color=blue]kdub:vec:zeroaxisfuzz[/color] a)
(if (and (> a (- 1E-13)) (< a 1E-13))
0.0
a
)
)
)
VectorList
)
)
[color=green];;
;;;-------------------------------------------------------------
;;;-------------------------------------------------------------[/color]
(princ)