Converting Polyline to Polyline2d

By Augusto Goncalves

There is a method called Polyline.ConvertTo that can convert a lightweight polyline into a polyline 2d object, but this method requires a special treatment.

First, it is required to use StartOpenCloseTransaction method to create a new transaction, instead regular StartTransaction. Second, remove the old polyline and append the newly created polyline 2d.

ObjectId plineId = // obtain here…

Database db =

  Application.DocumentManager.MdiActiveDocument.Database;

using (Transaction t =

  db.TransactionManager.StartOpenCloseTransaction())

{

  using (Polyline pline = (Polyline)

    t.GetObject(plineId, OpenMode.ForWrite))

  {

    t.AddNewlyCreatedDBObject(pline, false);

    Polyline2d poly2 = pline.ConvertTo(true);

    t.AddNewlyCreatedDBObject(poly2, true);

    t.Commit();

  }

}


Comments

One response to “Converting Polyline to Polyline2d”

  1. Thanks. I finally know for why the second argument of AddNewlyCreatedDBObject exists.

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading