<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic converting 2dpolyline to regular polyline in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/converting-2dpolyline-to-regular-polyline/m-p/3780042#M51123</link>
    <description>&lt;P&gt;Although I have found code that should allow me to convert 2dpolylines to regular polylines, I am having troubles implementing it. &amp;nbsp;At first I got the eInvalid Input but have since fixed that. &amp;nbsp;However, the error now is that there is no error. &amp;nbsp;Autocad just seems to lock up but I can still switch to visual studio and look at my code. &amp;nbsp;It as though Autocad thinks it is doing something but my code is not doing anything. &amp;nbsp;I can scroll around.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code is this:&lt;/P&gt;&lt;PRE&gt;        Try
            Dim acDrawing As Document = Application.DocumentManager.MdiActiveDocument
            Using acDrawingLock As DocumentLock = acDrawing.LockDocument
                Using acTransaction As Transaction = acDrawing.Database.TransactionManager.StartTransaction
                    Dim acBlockTable As BlockTable = acTransaction.GetObject(acDrawing.Database.BlockTableId, OpenMode.ForWrite)
                    Dim acBlockTableRecord As BlockTableRecord = acTransaction.GetObject(acBlockTable("*MODEL_SPACE"), OpenMode.ForWrite)
                    For Each Id As ObjectId In acBlockTableRecord
                        If Id.ObjectClass.Name = "AcDb2dPolyline" Then
                            Dim acPolyline2d As Polyline2d = Id.GetObject(OpenMode.ForWrite, True)
                            Dim acPolyLine As New Polyline()
                            acPolyLine.ConvertFrom(acPolyline2d, True)
                        End If
                    Next
                    acTransaction.Commit()
                End Using
            End Using
        Catch ex As System.Exception
            MsgBox(ex.ToString)
        End Try&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Anyone have any ideas? &amp;nbsp;It appears to hang on the acpolyline.convertofrm(acpolyline2d, true) line.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a bunch,&lt;/P&gt;</description>
    <pubDate>Wed, 13 Feb 2013 20:56:21 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2013-02-13T20:56:21Z</dc:date>
    <item>
      <title>converting 2dpolyline to regular polyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/converting-2dpolyline-to-regular-polyline/m-p/3780042#M51123</link>
      <description>&lt;P&gt;Although I have found code that should allow me to convert 2dpolylines to regular polylines, I am having troubles implementing it. &amp;nbsp;At first I got the eInvalid Input but have since fixed that. &amp;nbsp;However, the error now is that there is no error. &amp;nbsp;Autocad just seems to lock up but I can still switch to visual studio and look at my code. &amp;nbsp;It as though Autocad thinks it is doing something but my code is not doing anything. &amp;nbsp;I can scroll around.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code is this:&lt;/P&gt;&lt;PRE&gt;        Try
            Dim acDrawing As Document = Application.DocumentManager.MdiActiveDocument
            Using acDrawingLock As DocumentLock = acDrawing.LockDocument
                Using acTransaction As Transaction = acDrawing.Database.TransactionManager.StartTransaction
                    Dim acBlockTable As BlockTable = acTransaction.GetObject(acDrawing.Database.BlockTableId, OpenMode.ForWrite)
                    Dim acBlockTableRecord As BlockTableRecord = acTransaction.GetObject(acBlockTable("*MODEL_SPACE"), OpenMode.ForWrite)
                    For Each Id As ObjectId In acBlockTableRecord
                        If Id.ObjectClass.Name = "AcDb2dPolyline" Then
                            Dim acPolyline2d As Polyline2d = Id.GetObject(OpenMode.ForWrite, True)
                            Dim acPolyLine As New Polyline()
                            acPolyLine.ConvertFrom(acPolyline2d, True)
                        End If
                    Next
                    acTransaction.Commit()
                End Using
            End Using
        Catch ex As System.Exception
            MsgBox(ex.ToString)
        End Try&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Anyone have any ideas? &amp;nbsp;It appears to hang on the acpolyline.convertofrm(acpolyline2d, true) line.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a bunch,&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2013 20:56:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/converting-2dpolyline-to-regular-polyline/m-p/3780042#M51123</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-02-13T20:56:21Z</dc:date>
    </item>
    <item>
      <title>Re: converting 2dpolyline to regular polyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/converting-2dpolyline-to-regular-polyline/m-p/3780087#M51124</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class="hps alt-edited"&gt;As I know&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;one of the problems&lt;/SPAN&gt; &lt;SPAN class="hps alt-edited"&gt;- using&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;transactions.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Try samples and explanation:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://adndevblog.typepad.com/autocad/2012/05/converting-a-polyline2d-to-polyline.html" target="_self"&gt;Converting a Polyline2d to Polyline&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="http://adndevblog.typepad.com/autocad/2012/06/converting-polyline-to-polyline2d.html" target="_self"&gt;Converting a Polyline to Polyline2d&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Also Polyline2d have to be simple (&lt;SPAN class="Element146"&gt;SimplePoly&lt;/SPAN&gt;) or fit (&lt;SPAN class="Element146"&gt;FitCurvePoly&lt;/SPAN&gt;) and has not any Xdata attached to vertexes.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2013 21:51:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/converting-2dpolyline-to-regular-polyline/m-p/3780087#M51124</guid>
      <dc:creator>Alexander.Rivilis</dc:creator>
      <dc:date>2013-02-13T21:51:14Z</dc:date>
    </item>
    <item>
      <title>Re : converting 2dpolyline to regular polyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/converting-2dpolyline-to-regular-polyline/m-p/3780109#M51125</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You have to add the newly created polyline to the Database (and erase the polyline 2d).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's a quick and dirty C# snippet:&lt;/P&gt;&lt;PRE&gt;            Document doc = AcAp.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            using (doc.LockDocument())
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTableRecord mSpace =
                    (BlockTableRecord)SymbolUtilityServices
                    .GetBlockModelSpaceId(db)
                    .GetObject(OpenMode.ForWrite);
                RXClass rxc = RXClass.GetClass(typeof(Polyline2d));
                foreach (ObjectId id in mSpace)
                {
                    if (id.ObjectClass == rxc)
                    {
                        Polyline2d pl2d = (Polyline2d)tr.GetObject(id, OpenMode.ForWrite);
                        if (pl2d.PolyType != Poly2dType.CubicSplinePoly &amp;amp;&amp;amp;
                            pl2d.PolyType != Poly2dType.QuadSplinePoly)
                            using (Polyline pline = new Polyline())
                            {
                                pline.ConvertFrom(pl2d, false);
                                mSpace.AppendEntity(pline);
                                tr.AddNewlyCreatedDBObject(pline, true);
                                pl2d.Erase();
                            }
                    }
                }
                tr.Commit();
            }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2013 22:03:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/converting-2dpolyline-to-regular-polyline/m-p/3780109#M51125</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2013-02-13T22:03:45Z</dc:date>
    </item>
    <item>
      <title>Re : converting 2dpolyline to regular polyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/converting-2dpolyline-to-regular-polyline/m-p/3780120#M51126</link>
      <description>&lt;P&gt;Hi, Gilles!&lt;/P&gt;
&lt;P&gt;Are you sure that Transaction can be using in that context?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2013 22:16:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/converting-2dpolyline-to-regular-polyline/m-p/3780120#M51126</guid>
      <dc:creator>Alexander.Rivilis</dc:creator>
      <dc:date>2013-02-13T22:16:06Z</dc:date>
    </item>
    <item>
      <title>Re: converting 2dpolyline to regular polyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/converting-2dpolyline-to-regular-polyline/m-p/3780128#M51127</link>
      <description>&lt;P&gt;I tried the code from that link, but I was having troubles getting it to work.&amp;nbsp; It could have something to do with me translating to VB.net.&amp;nbsp; Perhaps my translation was messed up.&amp;nbsp; Do you have a quick translation?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2013 22:24:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/converting-2dpolyline-to-regular-polyline/m-p/3780128#M51127</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-02-13T22:24:49Z</dc:date>
    </item>
    <item>
      <title>Re : converting 2dpolyline to regular polyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/converting-2dpolyline-to-regular-polyline/m-p/3780129#M51128</link>
      <description>&lt;P&gt;Thanks Gile,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had come across that code at one point in my travels, but didnt think it did what I wanted it to do.&amp;nbsp; I will try that next.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2013 22:26:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/converting-2dpolyline-to-regular-polyline/m-p/3780129#M51128</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-02-13T22:26:32Z</dc:date>
    </item>
    <item>
      <title>Re : converting 2dpolyline to regular polyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/converting-2dpolyline-to-regular-polyline/m-p/3780135#M51129</link>
      <description>&lt;PRE&gt;' Translated C#-&amp;gt;VB.NET code:
' &lt;A href="http://adndevblog.typepad.com/autocad/2012/05/converting-a-polyline2d-to-polyline.html" target="_blank"&gt;http://adndevblog.typepad.com/autocad/2012/05/converting-a-polyline2d-to-polyline.html&lt;/A&gt;
&amp;lt;CommandMethod("TestConvertPoly")&amp;gt; _
Public Sub testConvertPoly()
    Dim doc As Document = Application.DocumentManager.MdiActiveDocument
    Dim db As Database = doc.Database
    Dim ed As Editor = doc.Editor
    ' select the entity
    Dim res As PromptEntityResult = ed.GetEntity("Select PolyLine: ")
    ' if ok
    If res.Status = PromptStatus.OK Then

        ' use the using keyword so that the objects auto-dispose

        '(close)  at the end of the brace

        ' open for write otherwise ConvertFrom will fail


        Using ent As Entity = DirectCast(res.ObjectId.Open(OpenMode.ForRead), Entity)

            ' if it's a polyline2d

            If TypeOf ent Is Polyline2d Then


                Dim poly2d As Polyline2d = DirectCast(ent, Polyline2d)

                poly2d.UpgradeOpen()


                ' again use the using keyword to ensure auto-closing


                Using poly As New Autodesk.AutoCAD.DatabaseServices.Polyline()

                    poly.ConvertFrom(poly2d, True)

                End Using

            End If

        End Using
    End If

End Sub

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2013 22:39:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/converting-2dpolyline-to-regular-polyline/m-p/3780135#M51129</guid>
      <dc:creator>Alexander.Rivilis</dc:creator>
      <dc:date>2013-02-13T22:39:52Z</dc:date>
    </item>
    <item>
      <title>Re : converting 2dpolyline to regular polyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/converting-2dpolyline-to-regular-polyline/m-p/3780211#M51130</link>
      <description>&lt;P&gt;Thanks Alexander and everyone who has help so far.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The vb.net code actually worked. &amp;nbsp;I think what happened to me preivously when attempting to use that code is that I saw a message about the Open function being obsolete to use GetObject instead. &amp;nbsp;So I did, but that didnt work. &amp;nbsp;When I actually used the Open the way you have it in your example code and ignored that little message, everything worked beautifully.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help. &amp;nbsp;I greatly appreciate it!&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2013 01:49:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/converting-2dpolyline-to-regular-polyline/m-p/3780211#M51130</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-02-14T01:49:44Z</dc:date>
    </item>
  </channel>
</rss>

