TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Fabricio28 on October 21, 2013, 12:14:01 PM

Title: verify closed polyline
Post by: Fabricio28 on October 21, 2013, 12:14:01 PM
Hi guys,

I used the join command to close a polygon. But for me the polygon was closed, in fact didn't, and gave me the wrong area.
I discover it through the properties palette.

Is there any lisp that can find the polygon is not closed?

I have about 50 polygons in my drawing.

Thank in advance
Title: Re: verify closed polyline
Post by: Tharwat on October 21, 2013, 12:26:19 PM
This is to check if an object (LWpolyline) is closed or not .

Code: [Select]
(vla-get-closed < vla-object >)
And it should return either of two , :vlax-false / :vlax-true
Title: Re: verify closed polyline
Post by: ronjonp on October 21, 2013, 12:29:40 PM
You can also check if the start and end point are equal to a fuzz tolerance.
Title: Re: verify closed polyline
Post by: rkmcswain on October 21, 2013, 01:13:56 PM
You can also check if the start and end point are equal to a fuzz tolerance.

The start and end points can be exactly the same and that does not make it a closed polyline.

See also:
http://www.4d-technologies.com/techcenter/pl/pl_open.lsp
http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Check-polyline-if-closed/m-p/861882#M87540
http://bit.ly/18D0Vve

Title: Re: verify closed polyline
Post by: CAB on October 21, 2013, 02:20:36 PM
Try this:
Code: [Select]
;;  get closed polyline
(setq ss (ssget  '((0 . "LWPOLYLINE,POLYLINE")(-4 . "&")(70 . 1))))
;;  gets not closed plines  by CAB,
(ssget "x"  '( (0 . "LWPOLYLINE") (-4 . "<not") (-4 . "&") (70 . 1) (-4 . "NOT>")) )
Title: Re: verify closed polyline
Post by: Fabricio28 on October 21, 2013, 03:29:42 PM
Thank for the quick replay, guys,

Someone could explain to me, why is that polygon gave me the wrong area?

Regards
Title: Re: verify closed polyline
Post by: ronjonp on October 21, 2013, 03:55:13 PM
Thank for the quick replay, guys,

Someone could explain to me, why is that polygon gave me the wrong area?

Regards


How are you calculating the area? I get the same area for both (closed or not).
Title: Re: verify closed polyline
Post by: Fabricio28 on October 21, 2013, 04:06:01 PM
Hi ronjonp,
Yes, I'm calculating the area. But before that I have to join the polylines.
I don't understand why that polygon gave me the wrong area.

Thank you

Title: Re: verify closed polyline
Post by: ronjonp on October 21, 2013, 04:11:08 PM
Hi ronjonp,
Yes, I'm calculating the area. But before that I have to join the polylines.
I don't understand why that polygon gave me the wrong area.

Thank you


Are you using code to get the areas? If so, post what function you're using.
Title: Re: verify closed polyline
Post by: Fabricio28 on October 21, 2013, 04:15:23 PM
Yes. I'm using Areas to Field from Lee Mac.
But even area command from the autocad is give me the wrong area.

Code: [Select]
Command: area

Specify first corner point or [Object/Add area/Subtract area] <Object>: o

Select objects:

Area = 40939.78, Length = 862.45

should be something wrong with the polygon.
Title: Re: verify closed polyline
Post by: ronjonp on October 21, 2013, 04:20:16 PM
Must be something specific to your setup. I cannot reproduce the differing areas.  :?
Title: Re: verify closed polyline
Post by: Fabricio28 on October 21, 2013, 04:27:05 PM
Did you see my attached file?
Is it giving the wrong area? (40939.78)

I don't know what happened, maybe you're right should be something about the setup.

Title: Re: verify closed polyline
Post by: ronjonp on October 21, 2013, 04:28:49 PM
Did you see my attached file?
Is it giving the wrong area? (40939.78)


Yes and no.
Title: Re: verify closed polyline
Post by: snownut2 on October 21, 2013, 05:08:00 PM
Is the proper area listed in the properties box if you just high-lite the polyline ?
Title: Re: verify closed polyline
Post by: CAB on October 21, 2013, 05:28:05 PM
Both plines show the same area for me ACAD2006

Title: Re: verify closed polyline
Post by: ymg on October 21, 2013, 11:02:33 PM
Fabricio,

If you zoom the upper left of your polyline, the one on the right is actually self-crossing,
so I doubt that it is correct.

You can also see this if you Pedit then edit xertex and then follow the vertices.

Still the problem with the area remains.  It all has to do with the extra vertex that is created by
simply changing the property to closed.

If you actually remove that extra vertex your area is OK.

ymg
Title: Re: verify closed polyline
Post by: pBe on October 22, 2013, 03:55:48 AM

Command: area
Specify first corner point or [Object/Add area/Subtract area] <Object>: o
Select objects:
Cannot calculate the area of a self intersecting curve.
Select objects:



Explode the object... run overkill...
17 object(s) deleted. <-------

as ymg noted above...
Title: Re: verify closed polyline
Post by: DanW on October 22, 2013, 04:36:20 AM
I think the area command taking exception to self intesecting curves was a known issue for AutoCAD 2009 and 2010, but fixed in 2011 onwards.
Title: Re: verify closed polyline
Post by: Fabricio28 on October 22, 2013, 07:54:25 AM
 :-D
Thank you all of you guys for interested in my task.
I'm using autocad 2012

Fabricio,

If you zoom the upper left of your polyline, the one on the right is actually self-crossing,
so I doubt that it is correct.

You can also see this if you Pedit then edit xertex and then follow the vertices.

Still the problem with the area remains.  It all has to do with the extra vertex that is created by
simply changing the property to closed.

If you actually remove that extra vertex your area is OK.

ymg

Hi ymg,
My english is very poor and I haven't explained clearly my task.
The area of the polygon on the right is correct, even if I remove that extra vertex still the same area (5484.37).
But I don't know what is wrong with the polygon on the left, is the same polygon as on the right and give other area (40939.78).
Title: Re: verify closed polyline
Post by: pBe on October 22, 2013, 09:18:49 AM
I think the area command taking exception to self intesecting curves was a known issue for AutoCAD 2009 and 2010, but fixed in 2011 onwards.

Nice to know ADESK looked into that issue and had it fix.

Thank you for the info  DanW
Title: Re: verify closed polyline
Post by: pBe on October 22, 2013, 09:29:50 AM

Hi ymg,
My english is very poor and I haven't explained clearly my task.
The area of the polygon on the right is correct, even if I remove that extra vertex still the same area (5484.37).
But I don't know what is wrong with the polygon on the left, is the same polygon as on the right and give other area (40939.78).

Same as CAB and ronjonp, Besides the text entry with 40939.78 value, both pline entities give me the same area using list command, even with LM's A2F lisp
Title: Re: verify closed polyline
Post by: ymg on October 22, 2013, 10:43:41 PM
Fabricio,

Quote
But I don't know what is wrong with the polygon on the left, is the same polygon as on the right and give other area (40939.78)

O que estou dizendo é que o polilines não são os mesmos.

Aquele com a área errada à esquerda tem mais vértices, incluindo um extra no final que desequilibra o cálculo.

O comando "Overkill"  é seu amigo para este

ymg
Title: Re: verify closed polyline
Post by: Fabricio28 on October 23, 2013, 09:45:23 AM
Hi ymg,

Portuguese is better. lol

I understood what you meant, but didn't work.
Maybe the problem should be in my autocad 2012.

I've already used overkill command too, and the area is same.