最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

AutoCAD LISP where I can select the Polyline which bounds the selected Text - Stack Overflow

programmeradmin2浏览0评论

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.

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.

Share Improve this question edited yesterday Joseph Romero asked Feb 8 at 3:07 Joseph RomeroJoseph Romero 11 bronze badge New contributor Joseph Romero is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 3
  • Excuse me, what is the question? What have you tried so far? – Sergey A Kryukov Commented 2 days ago
  • Is it possible to select a Rectangle(polyline) using the Text inside it in AutoCAD? I don't know about programming LISP but I want to know if it can be done. – Joseph Romero Commented yesterday
  • Thank you for the answer. It's important to have a question in a question post. :-) – Sergey A Kryukov Commented 23 hours ago
Add a comment  | 

1 Answer 1

Reset to default 0

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.

Method 1: Crossing/Window Polygon Selection

This is likely the easiest method to tackle the problem, but has some drawbacks where performance is concerned.

The general algorithm is as follows:

  • For every polyline in the set:
    • Obtain the set of vertices defining the polyline (DXF group 10 entries in the DXF data).
    • Zoom the drawing area to a window which encloses all vertices (to do this, you can calculate the min & max X & Y coordinates in the set of vertices so as to obtain a rectangular window which encloses all points) - for this you can use either a command call (command "_.zoom" "_w" ...) or the COM ZoomWindow method of the Application class (vla-zoomwindow (vlax-get-acad-object) ...).
    • Use the 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.
    • Perform a Zoom > Previous to restore the previous view - (command "_.zoom" "_p" ...) or the COM ZoomPrevious method of the Application class (vla-zoomprevious (vlax-get-acad-object) ...).

Method 2: Ray-Casting

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.

Method 3: Bounds Checking

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.

发布评论

评论列表(0)

  1. 暂无评论