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

Convert CIRCLE to Polyline

21 REPLIES 21
Reply
Message 1 of 22
Alex.Andrews
33657 Views, 21 Replies

Convert CIRCLE to Polyline

Hi Folks,

could you please help me anyone to convert circle to Polyline. I need C# Code to complete this action?

Regards

Alex Andrews.

21 REPLIES 21
Message 2 of 22
TheCADnoob
in reply to: Alex.Andrews

Not sure there is a clean way to do this. There is no simple convert, but there are a couple methods to get a polyline from your circle. 

 

Probably the easiest is to use BOUNDRY command. 

 

You can also try splitting the circle into two arcs and then use PEDIT to convert the arc to poly lines

 

Another method it to create a circle with a polyline ellipse. Set PELLIPSE to 1 and new ellipses will be drawn as polylines

 

I also read about using the DONUT command but that similar to splitting it into two arcs. 

 

CADnoob

EESignature

Message 3 of 22
GrantsPirate
in reply to: Alex.Andrews

A quick search on the internet will give you solutions, probably all in lisp, but they work.


GrantsPirate
Piping and Mech. Designer
EXPERT ELITE MEMBER
Always save a copy of the drawing before trying anything suggested here.
----------------------------------------------------------------------------
If something I wrote can be interpreted two ways, and one of the ways makes you sad or angry, I meant the other one.

Message 4 of 22

Hi,

 

in AutoCAD I would trim the circle to get an arc, then use command _PEDIT and select this arc and chose then _CLOSE

For C# please look in that customization forum for AutoCAD and .NET >>>click<<< (I would start to create an object as described above and then use .NET to select and analyse this object).

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 5 of 22
Kent1Cooper
in reply to: Alex.Andrews

My AutoLisp routine to do that is the C2P command in CirclePolylineSwap.lsp, available >here<.  I don't know C#, but if anything in the C2P command there suggests an approach in C# terms, take whatever you can use.

Kent Cooper, AIA
Message 6 of 22
pendean
in reply to: Alex.Andrews

DONUT command
Message 7 of 22
lewis724
in reply to: Kent1Cooper

Is there a way to convert multiple circles to polylines using this LISP routine?  I have thousands of circles on a drawing that i'm trying to convert easily.  When I use C2P, it only converts the first circle.  Any help would be appreciated!

Message 8 of 22
vinodkl
in reply to: lewis724

Hi,

 

you can use QSELECT first and isolate the circles first then you can use the command C2P and select all the circles. Thats it. I tried it and it works. Also check if the system variable PICKADD is set to "2", may that's what causing the problem on your end.

--------------------------------------------------------------------------------------------------------------------------
ವಿನೋದ್ ಕೆ ಎಲ್( System Design Engineer)



Likes is much appreciated if the information I have shared is helpful to you and/or others.

Please mark "Accept as Solution" if my reply resolves the issue or answers your question, to help others in the community.
--------------------------------------------------------------------------------------------------------------------------
Message 9 of 22
Kent1Cooper
in reply to: lewis724


@lewis724 wrote:

Is there a way to convert multiple circles to polylines using this LISP routine?  I have thousands of circles on a drawing that i'm trying to convert easily.  When I use C2P, it only converts the first circle.  Any help would be appreciated!


It is designed to do more than one, but as suggested, your PICKADD System Variable may be set wrong.

 

I'm not sure this will make any difference, but I'm attaching my current file, which says it was last edited on the very date of that link Message, though the file attached there doesn't say that's the last-edited date.  I may have simply noticed and updated it in mine without re-posting at the time, without any other changes, but just in case I did improve on anything else, here it is.

Kent Cooper, AIA
Message 10 of 22
vbenoit
in reply to: Alex.Andrews

This is not as elegant as writing a lisp routine but, this is the way I did it.  I used MAPEXPORT and exported the circles as a line .shp file.  Then used MAPIMPORT to import that shapefile and they came in as polylines.  It took about 3 minutes for 664 circles so I am not sure the difference in timing between this method and the lisp routine.

Message 11 of 22
ida.ghobakhlou
in reply to: vbenoit

If you have access to Civil 3d you can easily do it with "MAPCLEAN" command

Message 12 of 22
leeminardi
in reply to: Alex.Andrews

You might also consider using the polygon command with a high number of sides.

lee.minardi
Message 13 of 22
dlanorh
in reply to: leeminardi

A closed lwpolyline with a bulge also works

 

(defun rh:c2p (ent / spc obj)
  (setq spc (vlax-get-property (vla-get-activedocument (vlax-get-acad-object)) (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace))
        obj (vlax-invoke spc 'addlightweightpolyline (apply 'append (list (reverse (cdr (reverse (vlax-curve-getstartpoint ent)))) (reverse (cdr (reverse (vlax-curve-getpointatparam ent pi)))))))
  )
  (vlax-put-property obj 'closed :vlax-true)
  (foreach x '(0 1) (vla-setbulge obj x -1.0))
  (vla-delete (vlax-ename->vla-object ent))
);end_defun

 

feed it an entity and it produces a polyline. If you want to keep the circle comment out the (vla-delete..)

I am not one of the robots you're looking for

Message 14 of 22
Kent1Cooper
in reply to: dlanorh

People seem to be forgetting that they're looking for C# code for this.  More AutoLisp routines than have already been suggested are not going to be their answer.

Kent Cooper, AIA
Message 15 of 22
Sea-Haven
in reply to: Kent1Cooper

Can not c# call a lisp ? Why not go down that path. VBA can call a lisp or use a send command method "(Load "Mycirc-pline")"

 

A quick google

https://forums.autodesk.com/t5/net/problem-calling-a-lisp-routine-from-c/td-p/6023176

Message 16 of 22
Sea-Haven
in reply to: dlanorh

Nice idea add on say another layer or delete.

 

Re comment elsewhere 1600 circles about 1 second to make.

Message 17 of 22
Raymarcher
in reply to: Sea-Haven

Use boundary in circle

Message 18 of 22
Robin_Lee
in reply to: Alex.Andrews

I wanted to do this myself and was hitting a wall. However, I found a simple solution.

 

First, use the PELLIPSE command and set the value to 1 (this converts an ellipse to a 2D polyline).

Second, draw and ellipse the same size as the circle you want. 

Third, click on the ellipse and edit the global width in the geometry section of properties.

 

I hope this helps 🙂

Message 19 of 22
Kent1Cooper
in reply to: Robin_Lee

It may be a way to draw a new Polyline in the shape of a Circle, but:

1.  It's not in C# code as in the original request;

2.  It doesn't convert an existing Circle to a Polyline as in the original request and the Topic heading;

3.  It results in a Polyline of 16 segments, when it can be done with no more than 2 by other suggested approaches.

 

Kent Cooper, AIA
Message 20 of 22
Robin_Lee
in reply to: Kent1Cooper

Dear Ken1Cooper (Consultant),

 

Thank you for the response. I must admit that using C# code in AutoCAD is beyond my abilities and I cannot help with that part of the request. The question asked how to convert a circle into a polyline and I like to keep things simple, so I provided a simple solution. Other suggestions may result in a circle with less segments, but they are far more complex than my solution. Therefore, if you like things to be complicated, then please ignore my solution and try one of the others! 😉

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

Post to forums  

Autodesk Design & Make Report

”Boost