Jump to content

Recommended Posts

Posted

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.

Posted

If you get the entity of the polygon you will found out that it is a LWPOLYLINE

so it is hard to get it from the command name of the entity ....

 

may be with some kind of ActiveX functions it might be possible.

 

Regards

 

Tharwat

Posted

Do you need to get the polygon entity information or are you just trying to use it for the zoom points?

If you just want to zoom to a specific text why not use AutoCAD’s find command? It has a zoom option.

Posted

I want to find out the polygon which surrounds the text value specified by the user. Then I want to use the zoom command with object option. For the object prompt I want to give the polygon as the object to be zoomed.

 

Find command does not have a command line version and secondly I want to zoom the polygon not the text inside it.

 

Thanks

Posted

You would have to know how far out from the text object you could go (since it's not touching). Would the polyline be on the same layer? In these situations, it's always best to post an example DWG.

 

Out of curiosity, what's the big deal if you zoom to the text of the polyline?

Posted

There is an AutoLISP function named TEXTBOX - this allows you to list the bounding box for a text entity (it returns two points).

It doesn't help you to zoom to the text entity using the bounding box and, maybe, an offset value?

 

Regards,

Posted

I think I got it now

  • Use getstring to get user input
  • Use ssget “X” with a filter for mtext and text and the user text
  • Retrieve the entity from the ssget selection set
  • Get the insert point of the text
  • Use the command –boundary with the insert point from the text
  • Use entlast to get the new boundary created
  • Use bounding box to get upper left and lower right points of new boundary
  • Use entdel to delete the boundary
  • Use the 2 points from bounding box to zoom window

Posted

Thanks to all those who are helping me

 

I think the reply from JohnM can solve my issue. The polygons are not regular so I cannot predict at what distance its boundaries will be from the text object. Basically I want to zoom to the polygon and not the text object but which polygon? depends on what text value is entered by user.

 

Thanks again.

Posted

Risky option, but if you are going to go that route, make sure you Zoom Extents before you try executing the -boundary command or it won't create anything (if outside of view).

Posted

alanjt

 

Can you suggest some better way to do that?

Posted
alanjt

 

Can you suggest some better way to do that?

 

 

You would have to know how far out from the text object you could go (since it's not touching). Would the polyline be on the same layer? In these situations, it's always best to post an example DWG.

 

Out of curiosity, what's the big deal if you zoom to the text of the polyline?

 

I'd figure a relative distance, based on the size and boundingbox of the text object and use polar to step out from the boundingbox points to get a bigger selection to feed to ssget "_C" p1 p2.

 

I just don't like the idea of creating an object with command to then use entlast to select and delete it. However, if you do take this route, make sure you store (entlast) to a value before you execute -boundary for a comparison. That way you know if it worked or not.

Posted
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.

 

Too much duplicate posts btw

Almost not tested

(vl-load-com)
; local function
; by Daly, Bill 
; [url]http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Inside-Outside/m-p/853949/highlight/true#M79607[/url]
;***************************************************************************
; 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'~

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...