Jump to content

nearest NOT specified Text object from specified point?


michaelback

Recommended Posts

Collect all text entities in the current space in a list. Sort that list based on the distance between the geometric center (or insertion point?) of each text and the given point.

Link to comment
Share on other sites

Like roy_043 you can speed up the process by using a polygon search around the point, limiting the distance away. the simplest comparison is to just get the distance from a point on the text to the point of interest Ie Lee-mac. You could though introduce something like a bounding box around the text to compare the 4 corners.

 

(vla-getboundingbox (setq blockobject  (vlax-ename->vla-object (car (entsel))))
'lowerleft 'upperright
)
(setq bmax (vlax-safearray->list upperright))
(setq bmin (vlax-safearray->list lowerleft))

 

Then make a box or a circle using 2 points and do a VL closestpointto and again only keep the smallest answer.

 

I am busy right now but a question do you want a pick pick point solution or will there be parts 2,3 and so on as request gets bigger. You have not said what you wnat to do once found.

Link to comment
Share on other sites

Something like the code below is what I had in mind. But I have skipped the sorted list as that would only slow things down.

(vl-load-com)

(defun KGA_Geom_ObjectMiddle (obj / ptBL ptTR)
 (vla-getboundingbox obj 'ptBL 'ptTR)
 (mapcar
   '/
   (mapcar '+ (vlax-safearray->list ptBL) (vlax-safearray->list ptTR))
   '(2.0 2.0 2.0)
 )
)

; (ClosestTxt (trans (getpoint "\nPoint: ") 1 0)) => #<VLA-OBJECT ...>
(defun ClosestTxt (pt / dis ret ss tmp)
 (if (ssget "_X" (list '(0 . "MTEXT,TEXT") (cons 410 (getvar 'ctab))))
   (progn
     (vlax-for obj (setq ss (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
       (cond
         ((not dis)
           (setq dis (distance pt (KGA_Geom_ObjectMiddle obj)))
           (setq ret obj)
         )
         ((> dis (setq tmp (distance pt (KGA_Geom_ObjectMiddle obj))))
           (setq dis tmp)
           (setq ret obj)
         )
       )
     )
     (vla-delete ss)
   )
 )
 ret
)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...