Originally Posted by
mdsalman2003
I want to write a program which does following
1. I have a drawing in which each text value in the drawing is contained inside a polygon, but its not touching the polygon.
2. Program prompts user to input a text value.
3. After inputting the text value, the program searches the value and
if found in the drawing it zoom to that polygon which encloses the
specified text entity.
I am facing problem about how to select the polygon which is enclosing the specified text value. Please give some suggestion.
Thanks.
This one is very limited but hope this helps
(almost not tested)
Code:
(vl-load-com)
; local function
; by Daly, Bill
; http://forums.autodesk.com/t5/Visual...ht/true#M79607
;***************************************************************************
; Returns T if a point is inside the polygon bounded by an ordered list of points
(defun IsPointInPolygon ( ptTest ptList / pt numCross ptOutside ptLast
inside)
(setq ptOutside (polar (getvar "EXTMAX") (/ PI 4) 1.0))
(setq ptLast (car ptList) numCross 0)
(foreach pt ptList
(progn
(if (inters ptTest ptOutside pt ptLast T)
(setq numCross (1+ numCross))
)
(setq ptLast pt)
)
)
(if (inters ptTest ptOutside ptLast (car ptList))
(setq numCross (1+ numCross))
)
(if (= (rem numCross 2) 1)
(setq inside T)
(setq inside nil)
)
)
;;===============main program========================;
(defun C:textin (/ findwhat inspoint dp plineobj points poly polyset textent
textset textsize textstyle up)
(setq findwhat (getstring "\nEnter text to search for: ")
textstyle (getstring T "\n Enter textstyle: ")
textsize (getreal "\nEnter text size: ")
)
(vl-cmdf "._zoom" "_E")
(setq textset (ssget "_X" (list (cons 0 "*TEXT")
(cons 410 (getvar "CTAB"))
(cons 7 textstyle)
(cons 40 textsize)
(cons 1 findwhat)
))
)
(if (> (sslength textset) 1)
(progn
(alert "More than 1 text found. Exit")
(exit)(princ))
(progn
(setq textent (ssname textset 0)
inspoint (trans (cdr (assoc 10 (entget textent))) 1 0))
)
)
(setq polyset (ssget "_X" (list (cons 0 "LWPOLYLINE")
(cons 70 1);<--closed
)))
(while (setq poly (ssname polyset 0))
(setq points (vl-remove-if 'not
(mapcar (function (lambda(x)
(if (= 10 (car x))(cdr x))))
(entget poly)))
)
(if (IsPointInPolygon inspoint points)
(progn
(setq plineobj (vlax-ename->vla-object
poly))
(vla-getboundingbox plineobj 'dp 'up)
(vla-zoomwindow (vla-get-application plineobj) dp up)
)
)
(ssdel poly polyset)
)
(princ)
)
~'J'~