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
Solved! Go to Solution.
Solved by Jeff_M. Go to 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); }
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
Can't find what you're looking for? Ask the community or share your knowledge.