I am sure this worked in acad 2012 but crashes in 2013
As Jeff has mentioned in a post I am using .StartOpenCloseTransaction()
[CommandMethod("poly2")]
public static void poly2dt()
{
Document doc = acadApp.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
RXClass P2dClass = RXClass.GetClass(typeof(Polyline2d));
PromptEntityOptions peo = new PromptEntityOptions("Select an entity:");
peo.SetRejectMessage("Must be a 2d:");
peo.AddAllowedClass(typeof(Polyline2d), true);
PromptEntityResult per = ed.GetEntity(peo);
if (per.Status != PromptStatus.OK) return;
ObjectId entId=per.ObjectId;
using (Transaction tr = db.TransactionManager.StartOpenCloseTransaction())
{
if (entId.ObjectClass == P2dClass)
{
Polyline2d p2d = tr.GetObject(entId, OpenMode.ForRead) as Polyline2d;
if (p2d == null) return;
if (p2d.PolyType != Poly2dType.SimplePoly)return;
try
{
p2d.UpgradeOpen();
Polyline pline = new Polyline();
pline.ConvertFrom((Entity)p2d, true);
}
catch (System.Exception ex)
{
ed.WriteMessage(Environment.NewLine + ex);
throw;
}
}
tr.Commit();
}
} // end poly2d