michaelback Posted December 28, 2017 Share Posted December 28, 2017 How can we find nearest NOT specified Text/Mtext object from specified point? Thanks Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted December 28, 2017 Share Posted December 28, 2017 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. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 28, 2017 Share Posted December 28, 2017 Here's an old example which uses the text alignment point: http://www.cadtutor.net/forum/showthread.php?67654-Moving-Text-Block-to-adjacent-point&p=463442&viewfull=1#post463442 Quote Link to comment Share on other sites More sharing options...
michaelback Posted December 28, 2017 Author Share Posted December 28, 2017 Any example doint that measurment between text insertion point and given point? Quote Link to comment Share on other sites More sharing options...
BIGAL Posted December 29, 2017 Share Posted December 29, 2017 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. Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted December 29, 2017 Share Posted December 29, 2017 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 ) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.