Author Topic: Convert poly2d again  (Read 2291 times)

0 Members and 1 Guest are viewing this topic.

Bryco

  • Water Moccasin
  • Posts: 1883
Convert poly2d again
« on: October 31, 2012, 07:49:29 PM »
I am sure this worked in acad 2012 but crashes in 2013
As Jeff has mentioned in a post I am using .StartOpenCloseTransaction()

Code: [Select]
        [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 

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Convert poly2d again
« Reply #1 on: November 26, 2013, 01:22:11 PM »

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Convert poly2d again
« Reply #2 on: November 26, 2013, 03:49:36 PM »
Did you try using StartTransaction instead?  I've found that unless I do exactly as the name suggest, StartOpenCloseTransaction, I get errors now and then.  So once I decide to make a call to UpgradeOpen then I'm using StartTransaction instead.  HostApplication services is another place that likes to blow up StartOpenCloseTransaction too.

I'd use Open/Close more but Autodesk has marked the methods as deprecated and ReSharper doesn't like it.
Revit 2019, AMEP 2019 64bit Win 10