Reputation: 1
I work with lots of rectangles(POLYLINE) with an ID name(TEXT) inside them. I need to separate each Recatngles by Layer depending on their ID name. So to make things a bit easier, I want to be able to select the Polyline using the Text inside each Rectangles. Can this be done by a LISP?
I don't know anything about programming so I need help from the gurus here.
Thank you.
Upvotes: 0
Views: 33
Reputation: 16015
The short answer is yes, it's possible.
There are various ways to achieve this, but the success of the algorithm that you opt to implement will depend somewhat on the typical structure of your drawings (e.g. how congested the drawing is or whether polylines have concave sections which contain text from other polylines etc.).
For each of the methods I describe below, you'll first need to use ssget
to obtain a set of all candidate polylines; you can then use various techniques to associate each polyline in the set with a given text object.
This is likely the easiest method to tackle the problem, but has some drawbacks where performance is concerned.
The general algorithm is as follows:
(command "_.zoom" "_w" ...)
or the COM ZoomWindow
method of the Application class (vla-zoomwindow (vlax-get-acad-object) ...)
.ssget
function with a WP
(Window Polygon) or CP
(Crossing Polygon) mode string and the set of polyline vertices along with an appropriate filter list targeting TEXT
entities (and perhaps other properties, such as layer) to obtain a set of text objects residing within the polyline.(command "_.zoom" "_p" ...)
or the COM ZoomPrevious
method of the Application class (vla-zoomprevious (vlax-get-acad-object) ...)
.An alternative method is to cast a ray (an infinite line) from the insertion point or alignment point of the text object and check the number of times that it intersects a polyline in the set - you can use the COM IntersectWith
method to achieve this.
If the number of intersections is odd, the text object resides within the polyline - though, there are a few caveats to this method, e.g. accounting for if the ray exactly passes through the vertex of a concave edge, which could result in a false positive/negative.
A straightforward approach might be to check whether the insertion point or alignment point of the text object simply falls within the rectangular bounds of the polyline, and, if so, associated the text to the polyline.
The advantage of this method is the speed of the check (simply checking whether the X & Y coordinate values fall within a given range), but the method could yield false positives if, for example, the polyline has exaggerated concave sections which contain text that is to be associated with other polylines.
Upvotes: 0