.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Convert segment of polyline into arc

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
youssefGC
232 Views, 2 Replies

Convert segment of polyline into arc

Hi everyone,


How can I convert a segment of a polyline (where bulge ≠ 0) into an arc?

 

Thank you.

 

2 REPLIES 2
Message 2 of 3
_gile
in reply to: youssefGC

Hi,

You can check if a polyline segment is an arc using the Polyline.GetSegmentType method.

If the result is SegmentType.Arc, you can get the corresponding CircularArc3d using the Polyline.GetArcSegmentAt method.

If needed, you can convert the returned CircularArc3d into an Arc entity with the Curve.CreateFromGeCurve mehod.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 3
youssefGC
in reply to: _gile

Thank you. indeed, I tried to implement this code based on your method, and it works well for me.

[CommandMethod("ConvertToArc")]
        static public void runConversion()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            int indexOfArc = 0;
            PromptEntityResult acSSPrompt = ed.GetEntity("Select the polyline target");

            if (acSSPrompt.Status != PromptStatus.OK)
                return;

            using (Transaction Tx = db.TransactionManager.StartTransaction())
            {
                var btr = (BlockTableRecord)Tx.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                Polyline pl = Tx.GetObject(acSSPrompt.ObjectId, OpenMode.ForRead) as Polyline;

                if (pl!=null && pl.GetSegmentType(indexOfArc) == SegmentType.Arc)
                {
                    CircularArc3d clrArc = pl.GetArcSegmentAt(indexOfArc);
                    //Arc newArc = new Arc(clrArc.Center, clrArc.Radius, clrArc.StartAngle, clrArc.EndAngle);
                    Arc newArc = Curve.CreateFromGeCurve(clrArc as Curve3d) as Arc;

                    newArc.ColorIndex = 1;
                    btr.AppendEntity(newArc);
                    Tx.AddNewlyCreatedDBObject(newArc, true);
                }
                Tx.Commit();
            }
        }

 

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report