Convert CIRCLE to Polyline

Convert CIRCLE to Polyline

Anonymous
Not applicable
64,120 Views
28 Replies
Message 1 of 29

Convert CIRCLE to Polyline

Anonymous
Not applicable

Hi Folks,

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

Regards

Alex Andrews.

0 Likes
64,121 Views
28 Replies
Replies (28)
Message 21 of 29

ralph.pyka
Observer
Observer

This worked very well.  Thank you for sharing a nice solution.

0 Likes
Message 22 of 29

jbrissonHSYRW
Participant
Participant

This is what I've done and it has worked very well for me.  I've needed it for adding wipeouts behind circular blocks.

0 Likes
Message 23 of 29

Chris_Rose47VDB
Community Visitor
Community Visitor

Everytime I click on this link it takes me back to the forum main page. Where can I find the actual lsp?

0 Likes
Message 24 of 29

pendean
Community Legend
Community Legend

@Chris_Rose47VDB wrote:

Everytime I click on this link it takes me back to the forum main page. Where can I find the actual lsp?


Actual LISP was posted a few replies later 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-circle-to-polyline/m-p/89959...

 

Message 25 of 29

Kent1Cooper
Consultant
Consultant

@pendean wrote:.....

Actual LISP was posted a few replies later 


Thanks for the referral.  I've changed the link in the earlier Message to go there.

This site has lots of broken links like that now....

Kent Cooper, AIA
0 Likes
Message 26 of 29

mehrdad.design9
Explorer
Explorer

The easiest way is instead of drawing a circle, draw a polygon with 1000 sides. In CAD it looks like a circle. Then it will be a polyline and for example you can change the globe width of it easily.

0 Likes
Message 27 of 29

Sea-Haven
Mentor
Mentor

"draw a polygon with 1000 sides" for me that is not easiest. adds 1000 values to your dwg. It would be easier to just draw a pline using the ARC option and draw 2 arcs, similar to the donut command.

 

(command "pLINE"  p2 "w" 0.0 0.0 "a" "-180" "l" p5 "a"......     )
0 Likes
Message 28 of 29

Kent1Cooper
Consultant
Consultant

[Don't lose sight of the original question, which is not about drawing a circular Polyline, but rather about converting an already-drawn Circle into one.]

Kent Cooper, AIA
0 Likes
Message 29 of 29

_gile
Consultant
Consultant

Here's a C# method which creates a polyline matching a circle. It works whatever the circle plane.

public static Polyline CircleToPolyline(Circle circle)
{
    var normal = circle.Normal;
    var plane = new Plane(Point3d.Origin, circle.Normal);
    var center2d = circle.Center.Convert2d(plane);
    var pt1 = center2d + Vector2d.XAxis * circle.Radius;
    var pt2 = center2d - Vector2d.XAxis * circle.Radius;
    var pline = new Polyline(2);
    pline.AddVertexAt(0, pt1, 1.0, 0.0, 0.0);
    pline.AddVertexAt(1, pt2, 1.0, 0.0, 0.0);
    pline.Closed = true;
    pline.Normal = normal;
    pline.Elevation = circle.Center.TransformBy(Matrix3d.WorldToPlane(plane)).Z; ;
    return pline;
}

An equivalent LISP routine:

(defun circle2pline (circle / elst normal center vector)
  (if
    (and
      (setq elst (entget circle))
      (= (cdr (assoc 0 elst)) "CIRCLE")
      (setq normal (cdr (assoc 210 elst)))
      (setq center (cdr (assoc 10 elst)))
      (setq vector (list (cdr (assoc 40 elst)) 0.))
    )
     (entmakex
       (list
	 (cons 0 "LWPOLYLINE")
	 (cons 100 "AcDbEntity")
	 (cons 100 "AcDbPolyline")
	 (cons 90 2)
	 (cons 70 1)
	 (cons 38 (caddr center))
	 (cons 10 (mapcar '+ center vector))
	 (cons 42 1.)
	 (cons 10 (mapcar '- center vector))
	 (cons 42 1.)
	 (cons 210 normal)
       )
     )
  )
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes