Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Active Member
shashankabehera
Posts: 8
Registered: ‎04-10-2011
Message 21 of 23 (650 Views)

Re: Circle to Polyline, circular Polyline to Circle

03-09-2012 12:55 AM in reply to: Kent1Cooper

 

Hi,

 

Thanks for your prompt response, the Lisp is working fine. But I need to convert Polyline to circle as per attached DWG file. Can you please help me on this?

---
Regards,
Shashanka
*Expert Elite*
Kent1Cooper
Posts: 5,779
Registered: ‎09-13-2004
Message 22 of 23 (645 Views)

Re: Circle to Polyline, circular Polyline to Circle

03-09-2012 07:30 AM in reply to: shashankabehera

shashankabehera wrote:

....

Thanks for your prompt response, the Lisp is working fine. But I need to convert Polyline to circle as per attached DWG file. Can you please help me on this?


Those Polylines are not closed, and many [but not all] have one or more locations [not the same one(s) in each Polyline] with a whole pile of vertices [9 or so] in the same place, so they have a lot of zero-length segments.  Also, they're not quite regular [draw Lines across opposite vertices, and you'll see that they don't intersect in the center, and if you take your Units precision to 3 decimal places and grab all the Lines, you'll see that they're not the same length].  So they fail several of Pg2C's tests and don't "qualify" as regular polygons.

 

I suggest you set running Endpoint [only] object snap, and draw Circles with the 3Point option.  That could be automated something like this:

 

(setq pl (car (entsel "\nSelect at-least-25-sided Polyline to convert to Circle: ")))
(if (> (cdr (assoc 90 (entget pl))) 24)
  (progn
    (command "_.circle" "_3P"
      (vlax-curve-getPointAtParam pl 0)
      (vlax-curve-getPointAtParam pl 12)
      (vlax-curve-getPointAtParam pl 24)
    )
    (entdel pl)
  )
)

 

That does only one at a time, but it could be put into something that would allow selecting more than one.  But you'd have to be careful about what you select, because while it will decline to process your outline [too few vertices], it can't filter out any other Polylines with enough segments, since it has no criteria by which to judge whether they're approximately circular.

 

I briefly tried taking Pg2C and eliminating the checks on whether a polygon is closed and whether its segments are all the same length, but it didn't seem to work -- there are too many things about it that depend on the polygon being regular.  For instance, it finds the center using the point opposite the start, which will truly be opposite if it's a regular polygon, but having zero-length segments throws that off, so even if it calculates something, the resulting Circle won't be in the right place.

Kent Cooper
*Expert Elite*
Kent1Cooper
Posts: 5,779
Registered: ‎09-13-2004
Message 23 of 23 (619 Views)

Re: Circle to Polyline, circular Polyline to Circle

03-20-2012 07:27 PM in reply to: Kent1Cooper

Kent1Cooper wrote:

I had occasion to want to convert a Circle to a circular Polyline .... and while I was at it, ... to go the other way -- convert a circular Polyline (Donut) into a Circle. ....


Here's a further upgraded version of CirclePolylineSwap.lsp.  Two main improvements:

 

1.  Instead of converting only one thing at a time, both commands now let you pick as many objects as you want, and convert all qualifying objects in one running of the command.  (In P2C, if any of the selected Polylines have global non-zero width, it asks once about the Inside/Center/Outside positioning of the resulting Circle, and applies the same choice to all such Polylines in the selection.)

 

2.  P2C now uses a different method to check whether a Polyline is circular and should be converted to a Circle.  It no longer requires Polylines such as Donut makes, restricted to two equal half-circle arc segments.  It will convert any truly circular Polyline, no matter how many segments it has, and whether or not they're of equal included angles, as long as they don't backtrack over themselves.

Kent Cooper
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!