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

Convert Arcs to Polylines

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
wes.newman
17631 Views, 4 Replies

Convert Arcs to Polylines

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

4 REPLIES 4
Message 2 of 5
Jeff_M
in reply to: wes.newman

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
in reply to: Jeff_M

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
in reply to: Jeff_M

Jeff,

Just what I was after.

 

Thanks!!

Wes

Message 5 of 5

Thanks for the update.

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost