Jump to content

Finding polylines within others, in a selection


X11start

Recommended Posts

I have created a lisp that I routinely use to successively print various boards (A4 and A3 size), arranged in model space.
Basically, the command asks to select the tables I intend to print and as print coordinates it uses the frames (lwpolyline) it finds on layer "ZZ_FORMED".

 

(setq selpol(ssget
(LIST
  (cons -4 "<AND")
  (cons 0 "LWPOLYLINE")
  (cons 8 "ZZ_FORMED")
  (cons -4 "AND>")
)
))

 

The problem arises when by mistake, there are 2 overlapping panes, or one is inside another: e.g., the format frame that is also on layer "ZZ_FORMED", instead of on another layer that the lisp would ignore.
In these cases my drawing is mistakenly printed 2 times, once by taking the correct format and the other by taking the slightly smaller frame.

I would therefore like to find a way to find the error, which would allow me to stop my lisp and report the incorrect frame .... with a nice circle!

 

The workflow I thought I would use is as follows:

- I scroll one by one through all the selected polylines that are on the "ZZ_FORMED" layer.
- I create a list containing the vertices, of each polyline found.
- I create a second list containing the center of gravity (intersection point of the 1st with the 3rd vertex and the 2nd with the 4th).
- I scroll through the found barycenters one by one and check whether they lie within, not only the list of points considered
but also of another list. If so, it means that point is internal, not only of the figure whose barycenter it is,
but also of another: so it is an error.

 

I don't know if this is the correct flow or if there are faster solutions: I would like to avoid writing pages and pages of code, only to
then find out that with 4 VL-xx commands everything could be done!

Edited by X11start
Link to comment
Share on other sites

If you know the correct area of the polyline, it is very easy to check which polyline is wrong.

(vla-get-Area obj)

 

Link to comment
Share on other sites

On this page there's a function that detects overlapping polylines. According to the provider, it creates regions for both, subtracts one from the other, and compares the new area to the old. If all your plines are closed, it should work for you.

Link to comment
Share on other sites

The best suggestion of course is to use layouts and problems go away. 

 

Why is an inner frame on same Layer if you dont want to use it ? Put it on similar layer ZZ_FORMED_IN"

Link to comment
Share on other sites

8 hours ago, BIGAL said:

The best suggestion of course is to use layouts and problems go away. 

 

Why is an inner frame on same Layer if you dont want to use it ? Put it on similar layer ZZ_FORMED_IN"

In the company we CAN'T use layouts (the boss doesn't know how to use them... so we don't use them!), consequently we put all the drawings of the boards on template space.

The inner frame is on the same layer only by mistake: so I happen to print the same drawing 2 times.
Sometimes we need to print the drawing in A3 size (example: Armature and Carpentry of a panel), and then print only the Carpentry on A4 size.
For this we put the smaller format on another layer.... only by mistake it ends up on ZZ_FORMED.

My luck is that we always deal with polylines without arcs and with 4 points (the A3 to A4 format), so it is not difficult to find the center of gravity by means of a crossing and the INTERS command.
So as I wrote earlier, I will go through the various polylines one by one, extract their center of gravity and check if this center of gravity is also inside another polyline....

If I can this we I will try to put down some code.

 

Thank you very much Bigal

example.gif

Link to comment
Share on other sites

54 minutes ago, X11start said:

In the company we CAN'T use layouts (the boss doesn't know how to use them... so we don't use them!), consequently we put all the drawings of the boards on template space.

The inner frame is on the same layer only by mistake: so I happen to print the same drawing 2 times.
Sometimes we need to print the drawing in A3 size (example: Armature and Carpentry of a panel), and then print only the Carpentry on A4 size.
For this we put the smaller format on another layer.... only by mistake it ends up on ZZ_FORMED.

My luck is that we always deal with polylines without arcs and with 4 points (the A3 to A4 format), so it is not difficult to find the center of gravity by means of a crossing and the INTERS command.
So as I wrote earlier, I will go through the various polylines one by one, extract their center of gravity and check if this center of gravity is also inside another polyline....

If I can this we I will try to put down some code.

 

Thank you very much Bigal

example.gif

@X11start  Just add the dxf code for color 

 

(setq selpol-a4  (ssget
(LIST
  (cons -4 "<AND")
  (cons 0 "LWPOLYLINE")
   (cons 8 "ZZ_CARPENTERIA")
    (cons 62 colornumber) ; seem to be orange   
  (cons -4 "AND>")
)
))

or 

(setq selpol-a3  (ssget
(LIST
  (cons -4 "<AND")
  (cons 0 "LWPOLYLINE")
  (cons 8 "ZZ_FORMED")
  (cons 62 colornumber) ; seem to be gray 9  
  (cons -4 "AND>")
)
))

 

 

 

 

Link to comment
Share on other sites

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