Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Circle to Polyline, circular Polyline to Circle

52 REPLIES 52
Reply
Message 1 of 53
Kent1Cooper
28374 Views, 52 Replies

Circle to Polyline, circular Polyline to Circle

I had occasion to want to convert a Circle to a circular Polyline [so I could give it width, but I can imagine other reasons to want to do that].  Since Pedit won't do that conversion with a Circle as it will with a Line or an Arc, I looked for a routine here [assuming I would need to do this again from time to time], that would do the conversion by a simple selection of the Circle, so I didn't have to go through all the steps needed to construct an equivalent Polyline over the Circle and then erase the Circle.  I found some things that were prior to the existence of Lightweight Polylines, and/or that didn't take into account different Coordinate Systems, or a locked Layer, or non-default overrides of color, linetype, etc.

 

So I made one, and while I was at it, made one to go the other way -- convert a circular Polyline (Donut) into a Circle.  [I also found something here to do that, but along with the shortcomings above, it also didn't quite determine whether the selected Polyline is actually circular in Donut-like fashion.]  The Polyline-to-Circle converter works with either heavy or lightweight circular Polylines, and if the selected one has a global non-zero width, the User gets the choice of whether to draw the Circle along the Polyline's center-line or along its inside or outside edge.  It even saves that choice to offer as a default on further use.

 

CirclePolylineSwap.lsp contains two commands:  C2P [= Circle To Polyline] and P2C [= Polyline To Circle].  I hope others will find them useful.

Kent Cooper, AIA
52 REPLIES 52
Message 2 of 53
Kent1Cooper
in reply to: Kent1Cooper

Upgraded version.

 

The original didn't undo as you'd expect, which I've fixed.  There's nothing different about the operation of the commands.

Kent Cooper, AIA
Message 3 of 53
Anonymous
in reply to: Kent1Cooper

At first I was going to reply to use the donut command but I remembered that uses two arcs.

 

Drink some warm milk before you go to bed, then may you'd sleep and not program while you sleep. 

Message 4 of 53
Lee_Mac
in reply to: Kent1Cooper

Hi Kent,

 

Nice work Smiley Happy

 

A suggestion: you can use the following ssget mode to prompt for single selection (with behaviour akin to entsel), whilst excluding objects on locked layers:

 

(ssget "_+.:E:S:L")

 

Lee

Message 5 of 53
Anonymous
in reply to: Kent1Cooper

Kent, Since you do your work in AutoCAD 2004.  I thought I saw this fix in the forums but I can't seem to find it.  Dual monitor system, is there a setting to control which monitor it "sits" in upon opening each time.  I have tried the usual float, move and maximize but if I exit the program and restart it reverts back to the way it was.

 

I know Civil3D 2011 and AutoCAD 2010 don't to this, they stay anchored where you put them, so no display driver issue in my opinion.

Message 6 of 53
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

....Dual monitor system, is there a setting to control which monitor it "sits" in upon opening each time. ....


I can't help you there -- I only have a single monitor.

Kent Cooper, AIA
Message 7 of 53
Kent1Cooper
in reply to: Lee_Mac


@Lee_Mac wrote:

.... 

A suggestion: you can use the following ssget mode to prompt for single selection (with behaviour akin to entsel), whilst excluding objects on locked layers:

 

(ssget "_+.:E:S:L")

....


That looks potentially very useful.  But I can't find any documentation about use of the underscore or plus sign or period or :L parts of it in the AutoLISP Reference or AutoLISP Developer's Guide.  Can you explain what those parts do, whether the order of them matters, etc., or point me to something that does?

Kent Cooper, AIA
Message 8 of 53
Anonymous
in reply to: Kent1Cooper

Got this from the 2010 help files, if he is referencing 2012, there may be some new ones.  If you have 2004, their older. 

 

 

sel-method

A string that specifies the object selection method. Valid selection methods are

C Crossing selection.

CP Cpolygon selection (all objects crossing and inside of the specified polygon).

F Fence selection.

I Implied selection (objects selected while PICKFIRST is in effect).

L Last visible object added to the database.

P Last selection set created.

W Window selection.

WP WPolygon (all objects within the specified polygon).

X Entire database. If you specify the X selection method and do not provide a filter-list, ssget selects all entities in the database, including entities on layers that are off, frozen, and out of the visible screen.

:E Everything within the cursor's object selection pickbox.

:N Call ssnamex for additional information on container blocks and transformation matrices for any entities selected during the ssget operation. This additional information is available only for entities selected through graphical selection methods such as Window, Crossing, and point picks.

Unlike the other object selection methods, :N may return multiple entities with the same entity name in the selection set. For example, if the user selects a subentity of a complex entity such as a BlockReference, PolygonMesh, or old style polyline, ssget looks at the subentity that is selected when determining if it has already been selected. However, ssget actually adds the main entity (BlockReference, PolygonMesh, and so on) to the selection set. The result could be multiple entries with the same entity name in the selection set (each will have different subentity information for ssnamex to report).

:R Allows entities in a long transaction to be selected.

:S Allow single selection only.

:U Enables subentity selection. Cannot be combined with the duplicate (":D") or nested (":N") selection modes. In this mode, top-level entities are selected by default, but the user can attempt to select subentities by pressing the CTRL key while making the selection. This option is supported only with interactive selections, such as window, crossing, and polygon. It is not supported for all, filtered, or group selections.

:V Forces subentity selection. Treats all interactive, graphic selections performed by the user as subentity selections. The returned selection set contains subentities only. This option cannot be combined with the duplicate (":D") or nested (":N") selection modes. This option is supported only with interactive selections, such as window and crossing. It is not supported for all, filtered, or group selections.

pt1

 

Message 9 of 53
Lee_Mac
in reply to: Kent1Cooper


@Kent1Cooper wrote:

That looks potentially very useful.  But I can't find any documentation about use of the underscore or plus sign or period or :L parts of it in the AutoLISP Reference or AutoLISP Developer's Guide.  Can you explain what those parts do, whether the order of them matters, etc., or point me to something that does?


 The Help files don't document everything Smiley Wink

 

Attached is my personal reference for ssget, using information collected from various places. Note that some modes do not work with all versions and some are temperamental - but I'll let you experiment for yourself.

 

Lee

Message 10 of 53
Lee_Mac
in reply to: Lee_Mac

BTW, what's with the smiley's appearing in code blocks? I thought that was exactly what the code blocks were meant to prevent happening?

Message 11 of 53
Kent1Cooper
in reply to: Lee_Mac


@Lee_Mac wrote:

BTW, what's with the smiley's appearing in code blocks? I thought that was exactly what the code blocks were meant to prevent happening?


Even there you're not safe....  But if you're signed in and have your Settings right, you won't see the ones that are caused by colon-letter combinations anywhere, inside or outside code blocks.  See

http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Emoticon-Smiley-to-AutoLISP-Translato...

Kent Cooper, AIA
Message 12 of 53
Kent1Cooper
in reply to: Lee_Mac


@Lee_Mac wrote:
....

The Help files don't document everything

 

Attached is my personal reference for ssget, using information collected from various places. Note that some modes do not work with all versions and some are temperamental - but I'll let you experiment for yourself.

....


Thanks for that great resource!

Kent Cooper, AIA
Message 13 of 53
Lee_Mac
in reply to: Kent1Cooper


@Kent1Cooper wrote:

Even there you're not safe....  But if you're signed in and have your Settings right, you won't see the ones that are caused by colon-letter combinations anywhere, inside or outside code blocks.  See

http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Emoticon-Smiley-to-AutoLISP-Translato...


 That's disappointing - most other forums have this sorted Smiley Sad But thanks for the link Kent

Message 14 of 53
Lee_Mac
in reply to: Kent1Cooper


@Kent1Cooper wrote:

@Lee_Mac wrote:
....

The Help files don't document everything

 

Attached is my personal reference for ssget, using information collected from various places. Note that some modes do not work with all versions and some are temperamental - but I'll let you experiment for yourself.

....


Thanks for that great resource!


You're very welcome Kent Smiley Happy

Message 15 of 53
lai
Advocate
in reply to: Kent1Cooper

Hi Kent,

Recently i try your this lisp, but when i load my autocad with the lisp, i get this below error msg...May i know how or in anyway i can cancel this error msg? Please advise.

 

 

Regenerating model.

AutoCAD menu utilities loaded.

Type C2P to convert a Circle to its Polyline equivalent.

Type P2C to convert a circular Polyline to its Circle equivalent.; error: extra right paren on input

Command:

Command:

Message 16 of 53
Kent1Cooper
in reply to: lai


@lai wrote:

....when i load my autocad with the lisp, i get this below error msg....

 

Regenerating model.

AutoCAD menu utilities loaded.

Type C2P to convert a Circle to its Polyline equivalent.

Type P2C to convert a circular Polyline to its Circle equivalent.; error: extra right paren on input

....


It doesn't do that for me.  If you have it as a separate file loaded by something like acaddoc.lsp or an xxx.mnl file, or if you have included the two command definitions within some larger .lsp file, maybe there's something extra in the surrounding code.

 

The fact that it gives the prompts with the command names suggests that the appropriate code is loading -- do the commands work, despite the error message?

 

One test: load it separately from acaddoc.lsp or xxx.mnl or other means.  Either type APPLOAD and navigate to CirclePolylineSwap.lsp to load it, or type

 

(load "CirclePolylineSwap")

 

If it doesn't give you the error message, then the error is somewhere in the surrounding code that's loading it.

Kent Cooper, AIA
Message 17 of 53

Hi,

I’m looking for some lisp which can convert Polygon to circle, Please find attached DWG file.

Please help.

 

---

Regards,

Shashanka.

---
Regards,
Shashanka
Message 18 of 53


@shashankabehera wrote:

....I’m looking for some lisp which can convert Polygon to circle, Please find attached DWG file.

....


Those are octagons, made up of line segments.  The P2C command is designed to convert actually circular Polylines, with two half-circle arc segments [such as Donut makes] to Circles.

 

Here's a really simple routine, which does not check whether the selected Polyline is a regular octagon, but leaves it to you to use it only on such objects:

 

(defun C:82C (/ oct); = Octagon-to-Circle
  (vl-load-com)
  (setq oct (car (entsel "\nSelect regular octagon to convert to Circle: ")))
  (command
    "_.circle"
    "2P"
    (vlax-curve-getStartPoint oct)
    (vlax-curve-getPointAtParam oct 4)
  ); command
  (entdel oct)
); defun

 

If you use it on other kinds of things, you may get a Circle out of it, depending on what it is and how it's configured, but it may not relate as you expect to the selected object.  If you want it to be able to do polygons of other numbers of sides, or to check whether the selected Polygon is in fact regular, those can be done, but it would be a lot more complicated.

Kent Cooper, AIA
Message 19 of 53

Hi Kent,

Thanks for your prompt response. This routine is working fine.

I’ll appreciate if you can help me with the routine which can convert polygon of any no of sides to circle.

---
Regards,
Shashanka
Message 20 of 53


@shashankabehera wrote:

Hi Kent,

Thanks for your prompt response. This routine is working fine.

I’ll appreciate if you can help me with the routine which can convert polygon of any no of sides to circle.


Well, it took a little trial and error to get it working as I wanted, but here's a routine.  It could have been done sooner if it would merely handle a situation like your sample drawing, but I tried to make it as universal as possible.

 

The Pg2C command in the attached PolygonToCircle.lsp file converts any Polyline(s) [lightweight or heavy, 2D or 3D] that is closed, planar, has all straight segments of equal length, and all of whose vertices are the same distance from the center, including in different coordinate systems and with overrides of such things as linetype, color, etc.

 

As uploaded, it's set up to draw the CIRCUMscribing Circle(s) and to delete the polygon(s) that it converts, but it has instructions in it on what to do if you'd rather have it draw the INscribing Circle(s), and/or retain the polygon(s).  [Maybe later I'll make those choices into options within the command, so you can have them either way without multiple files.]

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost