.NET

Reply
Active Contributor as
Active Contributor
as
Posts: 41
Registered: ‎04-27-2005
Message 1 of 2 (366 Views)

Convert AcadPolyline To AcadLWPolyline

366 Views, 1 Replies
06-21-2005 07:26 AM
Is there a easy way to convert a AcadPolyline To a AcadLWPolyline.

Something like :
AcadLWpolyline = AcadPolyline.convertToLW

Harold van Aarsen
*Jim Awe
Message 2 of 2 (366 Views)

Re: Convert AcadPolyline To AcadLWPolyline

06-21-2005 08:23 AM in reply to: as
Try this function...

public void

ConvertPlines()

{

Editor ed =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

PromptSelectionOptions prOpts = new PromptSelectionOptions();

prOpts.MessageForAdding = "\nSelect AcDb2dPolylines";

TypedValue[] filter = new TypedValue[1];

Object obj1 = "POLYLINE";

filter[0] = new TypedValue(0, obj1);

SelectionFilter selFilter = new SelectionFilter(filter);


PromptSelectionResult res = ed.GetSelection(prOpts, selFilter);

if (res.Status != PromptStatus.OK)

return;


int successCount = 0;

int failedCount = 0;

Autodesk.AutoCAD.DatabaseServices.TransactionManager tm =
Utils.Db.GetCurDwg().TransactionManager;

using (Autodesk.AutoCAD.DatabaseServices.Transaction tr =
tm.StartTransaction()) {

ObjectId[] objIds = res.Value.GetObjectIds();

foreach (ObjectId objId in objIds) {

using (Entity oldPline = (Entity)objId.Open(OpenMode.ForWrite)) {

using (Polyline newPline = new Polyline()) {

try {

newPline.ConvertFrom(oldPline, true);

successCount++;

}

catch (Autodesk.AutoCAD.Runtime.Exception e) {

ed.WriteMessage("\nERROR: {0}", e.ErrorStatus.ToString());

failedCount++;

}

newPline.Close();

}

}

}


tr.Commit();

}

ed.WriteMessage("\nConverted {0:d} polylines.", successCount);

ed.WriteMessage("\nFailed to convert {0:d} polylines.", failedCount);

}

}

Sorry for the formatting... I can't seem to ever get that to work with
Outlook Express. Note. There are legitimate reasons it will fail to
convert, and thus the extra error checking. Some AcDb2dPolylines are things
like Fit curves and they don't convert. See the documentation of
ConvertFrom() for details.

Jim Awe

Autodesk, Inc.

wrote in message news:4880437@discussion.autodesk.com...
Is there a easy way to convert a AcadPolyline To a AcadLWPolyline.

Something like :
AcadLWpolyline = AcadPolyline.convertToLW

Harold van Aarsen
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.