Convert Arcs to Polylines

Convert Arcs to Polylines

wes_newman
Autodesk Autodesk
18,918 Views
4 Replies
Message 1 of 5

Convert Arcs to Polylines

wes_newman
Autodesk
Autodesk

I've got ObjectIds of a bunch of arcs that I need to convert to polylines for further processing.

Anyone know of a clean way to do this?

 

I was thinking of using the COM interface and sending the PEDIT command and converting the arcs.

The only problem is I don't know of a way to put the objectids into a selection set, then call the pedit command and use the previous selection.

Anyone know of a way to do this?

 

Thanks,
Wes

0 Likes
Accepted solutions (1)
18,919 Views
4 Replies
Replies (4)
Message 2 of 5

Jeff_M
Consultant
Consultant
Accepted solution

Here's something I did when I was learning, hope it helps.

        [CommandMethod("Arc2Poly")]
        public void arc2poly()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;
            PromptSelectionOptions psOpts = new PromptSelectionOptions();
            psOpts.MessageForAdding = "\nSelect arcs to convert: ";
            psOpts.MessageForRemoval = "\n...Remove arcs: ";
            TypedValue[] filter = { new TypedValue(0, "ARC") };
            SelectionFilter ssfilter = new SelectionFilter(filter);
            PromptSelectionResult psRes = ed.GetSelection(psOpts, ssfilter);
            if (psRes.Status != PromptStatus.OK)
                return;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable bt = (BlockTable)db.BlockTableId.GetObject(OpenMode.ForRead);
                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                foreach (ObjectId id in psRes.Value.GetObjectIds())
                {
                    Arc arc = (Arc)tr.GetObject(id, OpenMode.ForWrite);
                    Polyline poly = new Polyline();
                    poly.AddVertexAt(0, new Point2d(arc.StartPoint.X, arc.StartPoint.Y), GetArcBulge(arc), 0, 0);
                    poly.AddVertexAt(1, new Point2d(arc.EndPoint.X, arc.EndPoint.Y), 0, 0, 0);
                    poly.LayerId = arc.LayerId;
                    btr.AppendEntity(poly);
                    tr.AddNewlyCreatedDBObject(poly, true);
                    arc.Erase();
                }
                tr.Commit();
            }
        }

        private double GetArcBulge(Arc arc)
        {
            double deltaAng = arc.EndAngle - arc.StartAngle;
            if (deltaAng < 0)
                deltaAng += 2 * Math.PI;
            return Math.Tan(deltaAng * 0.25);
        }

 

Jeff_M, also a frequent Swamper
EESignature
Message 3 of 5

Alexander.Rivilis
Mentor
Mentor

And:

poly.Normal = arc.Normal;

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 4 of 5

wes_newman
Autodesk
Autodesk

Jeff,

Just what I was after.

 

Thanks!!

Wes

0 Likes
Message 5 of 5

wes_newman
Autodesk
Autodesk

Thanks for the update.

0 Likes