<?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 Re: Polyline3d.InsertVertexAt crashes Program in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/polyline3d-insertvertexat-crashes-program/m-p/7491375#M29169</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3118683"&gt;@bwang-tecoustics&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;I'll try next to insert the vertex out of the For each loop.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;The problem is not that. I wasn't looking closely at the code and didn't notice that the second For Each/Next loop is iterating over the ObjectIdCollection, rather than the Polyline itself. That should not be a problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When you say that InsertVertexAt() doesn't work, is there an exception being thrown? &amp;nbsp;If there is, you should display the exception on the text console using Editor.WriteMessage(), rather than in a message box, so that you can copy the exception text and paste it into a reply here, because 'not working' isn't very descriptive.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try adding the following line after the call to InsertVertexAt():&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;BR /&gt;   oEnt.InsertVertexAt(oVt.ObjectId, nVt)&lt;BR /&gt;   &lt;FONT color="#FF0000"&gt;nVt.Close()&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&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, 25 Oct 2017 19:01:14 GMT</pubDate>
    <dc:creator>ActivistInvestor</dc:creator>
    <dc:date>2017-10-25T19:01:14Z</dc:date>
    <item>
      <title>Polyline3d.InsertVertexAt crashes Program</title>
      <link>https://forums.autodesk.com/t5/net-forum/polyline3d-insertvertexat-crashes-program/m-p/7488233#M29165</link>
      <description>&lt;P&gt;I was testing to insert a vertex at a polyline using InsertVertexAt method. But it just crashes every time. Is there anything wrong? The code was copied from a vertex removal code. The removal worked fine. I then try to convert it to add a vertex just 10 units next to the index vertex and failed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        &amp;lt;CommandMethod("R3DV")&amp;gt; _
        Public Shared Sub RemoveVertex()


            Dim doc As Document = Application.DocumentManager.MdiActiveDocument

            Dim db As Database = doc.Database
            Dim ed As Editor = doc.Editor


            Using oTr As Transaction = db.TransactionManager.StartTransaction

                Dim ids As New ObjectIdCollection

                Dim options As New PromptEntityOptions(vbLf &amp;amp; "Pick a 3DPolyline:")

                options.SetRejectMessage("Select 3DPolyline only" + vbLf)
                options.AddAllowedClass(GetType(Polyline3d), True)

                Dim result As PromptEntityResult = ed.GetEntity(options)

                If result.Status &amp;lt;&amp;gt; PromptStatus.OK Then
                    Return
                End If

                ' Polyline3D object
                Dim oEnt As Polyline3d = TryCast(oTr.GetObject(result.ObjectId, OpenMode.ForRead), Polyline3d)


                ' Find each vertex in 3D Polyline
                For Each oVtId As ObjectId In oEnt

                    Dim oVt As PolylineVertex3d = TryCast(oTr.GetObject(oVtId, OpenMode.ForRead), PolylineVertex3d)

                    Dim oPko As New PromptKeywordOptions(vbLf &amp;amp; "Want to remove vertex at " + oVt.Position.ToString() + "?")
                    oPko.AllowNone = False
                    oPko.Keywords.Add("Yes")
                    oPko.Keywords.Add("No")
                    oPko.Keywords.[Default] = "No"

                    Dim oPkr As PromptResult = ed.GetKeywords(oPko)

                    If oPkr.Status = PromptStatus.OK AndAlso oPkr.StringResult = "Yes" Then
                        ids.Add(oVtId) ' ids stores verteies object id's.
                    End If
                Next

                For Each oVtId As ObjectId In ids

                    Dim oVt As PolylineVertex3d = TryCast(oTr.GetObject(oVtId, OpenMode.ForWrite), PolylineVertex3d)
                    Dim nVtP3d As Point3d = New Point3d(oVt.Position.X + 10, oVt.Position.Y, oVt.Position.Z)
                    Dim nVt As PolylineVertex3d = New PolylineVertex3d(nVtP3d)
                    Try
                        oEnt.InsertVertexAt(oVt, nVt)
                    Catch ex As Autodesk.AutoCAD.Runtime.Exception
                        MsgBox(ex.ToString)
                    End Try

                    'oVt.[Erase]()
                Next

                If ids.Count &amp;lt;&amp;gt; 0 Then

                    oEnt.UpgradeOpen() ' Upgrade open mode from readonly to write.
                    'oTr.AddNewlyCreatedDBObject(nVt, True)
                    oEnt.RecordGraphicsModified(True)
                End If

                oTr.Commit()
            End Using

        End Sub&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Oct 2017 20:27:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/polyline3d-insertvertexat-crashes-program/m-p/7488233#M29165</guid>
      <dc:creator>bwang-tecoustics</dc:creator>
      <dc:date>2017-10-24T20:27:28Z</dc:date>
    </item>
    <item>
      <title>Re: Polyline3d.InsertVertexAt crashes Program</title>
      <link>https://forums.autodesk.com/t5/net-forum/polyline3d-insertvertexat-crashes-program/m-p/7488401#M29166</link>
      <description>&lt;P&gt;As a general rule, you should first try to identify what is causing the crash by placing the entire method's body inside a Try block, and inside the following Catch block, display the exception in a message box.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your code uses try/catch to trap an exception thrown by InsertVertexAt(), but if the exception is thrown by other code, it will not be caught and you won't find out what code caused it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The other problem is that you are inserting vertices into the polyline while you are iterating over the existing vertices. You can't do that. You have to store all of the new vertices that you're going to insert in a List, and after you exit the For Each/Next loop, then you insert all of the new vertices from the list into the Polyline.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, I'll speculate&amp;nbsp;that your problem is either an eNotOpenForWrite because you are inserting vertices into the polyline (e.g., modifying it), before you call UpgradeOpen() to upgrade the polyline's open mode to OpenMode.ForWrite, or the problem is that you're inserting vertices while enumerating over the existing ones within a For Each/Next loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Oct 2017 21:43:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/polyline3d-insertvertexat-crashes-program/m-p/7488401#M29166</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2017-10-24T21:43:46Z</dc:date>
    </item>
    <item>
      <title>Re: Polyline3d.InsertVertexAt crashes Program</title>
      <link>https://forums.autodesk.com/t5/net-forum/polyline3d-insertvertexat-crashes-program/m-p/7490645#M29167</link>
      <description>&lt;P&gt;I made two changes and the code is working now.&lt;/P&gt;
&lt;P&gt;1. Move the UpgradeOpen to before the InsertVertexAt.&lt;/P&gt;
&lt;P&gt;2. Use InsertVertexAt(ObjectId, PolylineVertex3d) instead of InsertVertexAt(PolylineVertex3d, PolylineVertex3d). Still don't know why the InsertVertexAt(PolylineVertex3d, PolylineVertex3d) doesn't work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        &amp;lt;CommandMethod("R3DV")&amp;gt; _
        Public Shared Sub RemoveVertex()


            Dim doc As Document = Application.DocumentManager.MdiActiveDocument

            Dim db As Database = doc.Database
            Dim ed As Editor = doc.Editor


            Using oTr As Transaction = db.TransactionManager.StartTransaction

                Dim ids As New ObjectIdCollection

                Dim options As New PromptEntityOptions(vbLf &amp;amp; "Pick a 3DPolyline:")

                options.SetRejectMessage("Select 3DPolyline only" + vbLf)
                options.AddAllowedClass(GetType(Polyline3d), True)

                Dim result As PromptEntityResult = ed.GetEntity(options)

                If result.Status &amp;lt;&amp;gt; PromptStatus.OK Then
                    Return
                End If

                ' Polyline3D object
                Dim oEnt As Polyline3d = TryCast(oTr.GetObject(result.ObjectId, OpenMode.ForRead), Polyline3d)


                ' Find each vertex in 3D Polyline
                For Each oVtId As ObjectId In oEnt

                    Dim oVt As PolylineVertex3d = TryCast(oTr.GetObject(oVtId, OpenMode.ForRead), PolylineVertex3d)

                    Dim oPko As New PromptKeywordOptions(vbLf &amp;amp; "Want to remove vertex at " + oVt.Position.ToString() + "?")
                    oPko.AllowNone = False
                    oPko.Keywords.Add("Yes")
                    oPko.Keywords.Add("No")
                    oPko.Keywords.[Default] = "No"

                    Dim oPkr As PromptResult = ed.GetKeywords(oPko)

                    If oPkr.Status = PromptStatus.OK AndAlso oPkr.StringResult = "Yes" Then
                        ids.Add(oVtId) ' ids stores verteies object id's.
                    End If
                Next

                If ids.Count &amp;lt;&amp;gt; 0 Then

                    oEnt.UpgradeOpen() ' Upgrade open mode from readonly to write.
                    'oTr.AddNewlyCreatedDBObject(nVt, True)
                    oEnt.RecordGraphicsModified(True)
                End If

                For Each oVtId As ObjectId In ids

                    Dim oVt As PolylineVertex3d = TryCast(oTr.GetObject(oVtId, OpenMode.ForWrite), PolylineVertex3d)
                    Dim nVtP3d As Point3d = New Point3d(oVt.Position.X + 10, oVt.Position.Y, oVt.Position.Z)
                    Dim nVt As PolylineVertex3d = New PolylineVertex3d(nVtP3d)
                    Try
                        oEnt.InsertVertexAt(oVt.ObjectId, nVt)
                        'oEnt.InsertVertexAt(oVt, nVt)
                    Catch ex As Autodesk.AutoCAD.Runtime.Exception
                        MsgBox(ex.ToString)
                    End Try

                    'oVt.[Erase]()
                Next

                oTr.Commit()
            End Using

        End Sub&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Oct 2017 15:19:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/polyline3d-insertvertexat-crashes-program/m-p/7490645#M29167</guid>
      <dc:creator>bwang-tecoustics</dc:creator>
      <dc:date>2017-10-25T15:19:09Z</dc:date>
    </item>
    <item>
      <title>Re: Polyline3d.InsertVertexAt crashes Program</title>
      <link>https://forums.autodesk.com/t5/net-forum/polyline3d-insertvertexat-crashes-program/m-p/7490686#M29168</link>
      <description>&lt;P&gt;I'll try next to insert the vertex out of the For each loop.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2017 15:30:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/polyline3d-insertvertexat-crashes-program/m-p/7490686#M29168</guid>
      <dc:creator>bwang-tecoustics</dc:creator>
      <dc:date>2017-10-25T15:30:29Z</dc:date>
    </item>
    <item>
      <title>Re: Polyline3d.InsertVertexAt crashes Program</title>
      <link>https://forums.autodesk.com/t5/net-forum/polyline3d-insertvertexat-crashes-program/m-p/7491375#M29169</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3118683"&gt;@bwang-tecoustics&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;I'll try next to insert the vertex out of the For each loop.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;The problem is not that. I wasn't looking closely at the code and didn't notice that the second For Each/Next loop is iterating over the ObjectIdCollection, rather than the Polyline itself. That should not be a problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When you say that InsertVertexAt() doesn't work, is there an exception being thrown? &amp;nbsp;If there is, you should display the exception on the text console using Editor.WriteMessage(), rather than in a message box, so that you can copy the exception text and paste it into a reply here, because 'not working' isn't very descriptive.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try adding the following line after the call to InsertVertexAt():&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;BR /&gt;   oEnt.InsertVertexAt(oVt.ObjectId, nVt)&lt;BR /&gt;   &lt;FONT color="#FF0000"&gt;nVt.Close()&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&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, 25 Oct 2017 19:01:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/polyline3d-insertvertexat-crashes-program/m-p/7491375#M29169</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2017-10-25T19:01:14Z</dc:date>
    </item>
    <item>
      <title>Re: Polyline3d.InsertVertexAt crashes Program</title>
      <link>https://forums.autodesk.com/t5/net-forum/polyline3d-insertvertexat-crashes-program/m-p/7491596#M29170</link>
      <description>&lt;P&gt;When I use InsertVertexAt(PolylineVertex3d, PolylineVertex3d), it gives me this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="InsertVertexAt01.png" style="width: 459px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/417782i9DE517DFFF684D5B/image-size/large?v=v2&amp;amp;px=999" role="button" title="InsertVertexAt01.png" alt="InsertVertexAt01.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, the nVt.Close method is obsolete.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2017 20:20:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/polyline3d-insertvertexat-crashes-program/m-p/7491596#M29170</guid>
      <dc:creator>bwang-tecoustics</dc:creator>
      <dc:date>2017-10-25T20:20:29Z</dc:date>
    </item>
    <item>
      <title>Re: Polyline3d.InsertVertexAt crashes Program</title>
      <link>https://forums.autodesk.com/t5/net-forum/polyline3d-insertvertexat-crashes-program/m-p/7491779#M29171</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3118683"&gt;@bwang-tecoustics&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;When I use InsertVertexAt(PolylineVertex3d, PolylineVertex3d), it gives me this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, the nVt.Close method is obsolete.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Disregard what the compiler tells you about the Close() method, and use it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The other problem is that your code logic is broken. You test to see if the ObjectIdCollection's Count property is &amp;lt;&amp;gt; 0, and call UpgradeOpen(), but you don't exit the method if the count is 0, and instead, proceed without the UpgradeOpen() call. &amp;nbsp;The dialog you show an image of is not the dialog you show from the catch block in the code. Showing a dialog or message box could itself be causing a problem. Instead of doing that, write the exception to the command line, using Editor.WriteMessage().&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I converted your code to C#, corrected the aforementioned errors, and made a few other minor changes (shown in red), and the code runs without any problem:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;

namespace ClassLibrary2
{
   public static class InsertVertex3d
   {


      [CommandMethod("R3DV")]
      public static void RemoveVertex()
      {
         Document doc = Application.DocumentManager.MdiActiveDocument;
         Database db = doc.Database;
         Editor ed = doc.Editor;
         using(Transaction oTr = db.TransactionManager.&lt;FONT color="#FF0000"&gt;StartOpenCloseTransaction&lt;/FONT&gt;())
         {
            ObjectIdCollection ids = new ObjectIdCollection();
            PromptEntityOptions options = new PromptEntityOptions("\nPick a 3DPolyline:");
            options.SetRejectMessage("Select 3DPolyline only\n");
            options.AddAllowedClass(typeof(Polyline3d), true);
            PromptEntityResult result = ed.GetEntity(options);
            if(result.Status != PromptStatus.OK)
            {
               return;
            }
            // Polyline3D object
            Polyline3d oEnt = oTr.GetObject(result.ObjectId, OpenMode.ForRead) as Polyline3d;
&lt;FONT color="#FF0000"&gt;            if(oEnt == null)
            {
               ed.WriteMessage("\nSelected object is not a 3DPOLY");
               return;
            }&lt;/FONT&gt;            &lt;BR /&gt;            foreach(ObjectId oVtId in oEnt)
            {
               PolylineVertex3d oVt = oTr.GetObject(oVtId, OpenMode.ForRead) as PolylineVertex3d;
               PromptKeywordOptions oPko = new PromptKeywordOptions("\nWant to remove vertex at " + oVt.Position.ToString() + "?");
               oPko.AllowNone = false;
               oPko.Keywords.Add("Yes");
               oPko.Keywords.Add("No");
               oPko.Keywords.Default = "No";
               PromptResult oPkr = ed.GetKeywords(oPko);
               if(oPkr.Status == PromptStatus.OK &amp;amp;&amp;amp; oPkr.StringResult == "Yes")
               {
                  ids.Add(oVtId);
               }
            }
&lt;FONT color="#FF0000"&gt;            if(ids.Count == 0)
            {
               return;
            }&lt;/FONT&gt;            &lt;BR /&gt;            oEnt.UpgradeOpen();
            foreach(ObjectId oVtId in ids)
            {
               PolylineVertex3d oVt = oTr.GetObject(oVtId, OpenMode.ForWrite) as PolylineVertex3d;
               Point3d nVtP3d = new Point3d(oVt.Position.X + 10, oVt.Position.Y, oVt.Position.Z);
               PolylineVertex3d nVt = new PolylineVertex3d(nVtP3d);
               try
               {
                  oEnt.InsertVertexAt(oVt.ObjectId, nVt);
                  &lt;FONT color="#FF0000"&gt;nVt.Close();&lt;/FONT&gt;
               }
               catch(Autodesk.AutoCAD.Runtime.Exception ex)
               {
                  &lt;FONT color="#FF0000"&gt;ed.WriteMessage(ex.ToString());&lt;/FONT&gt;
                  return;
               }
               &lt;FONT color="#FF0000"&gt;oEnt.RecordGraphicsModified(true);&lt;/FONT&gt;
            }

            oTr.Commit();
         }

      }

   }
}&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Oct 2017 21:46:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/polyline3d-insertvertexat-crashes-program/m-p/7491779#M29171</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2017-10-25T21:46:59Z</dc:date>
    </item>
    <item>
      <title>Re: Polyline3d.InsertVertexAt crashes Program</title>
      <link>https://forums.autodesk.com/t5/net-forum/polyline3d-insertvertexat-crashes-program/m-p/7493383#M29172</link>
      <description>&lt;P&gt;Thank you very much.&lt;/P&gt;
&lt;P&gt;The reason I didn't post the exception is that the program just crashes everytime and doesn't give itself a&amp;nbsp;chance to show the exception.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2017 12:44:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/polyline3d-insertvertexat-crashes-program/m-p/7493383#M29172</guid>
      <dc:creator>bwang-tecoustics</dc:creator>
      <dc:date>2017-10-26T12:44:56Z</dc:date>
    </item>
    <item>
      <title>Re: Polyline3d.InsertVertexAt crashes Program</title>
      <link>https://forums.autodesk.com/t5/net-forum/polyline3d-insertvertexat-crashes-program/m-p/7493420#M29173</link>
      <description>&lt;P&gt;Interesting. Your code just works the same way as mine. If I change your code "oEnt.InsertVertexAt(oVt.ObjectId, nVt);" to "oEnt.InsertVertexAt(oVt, nVt);", my AutoCAD crashes. So, there is a problem with the InsertVertexAt(Polyline3dVertex3d, Polyline3dVertex3d) method. I'll just use the InsertVertexAt(ObjectId, Polyline3dVertex3d) method then.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2017 12:57:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/polyline3d-insertvertexat-crashes-program/m-p/7493420#M29173</guid>
      <dc:creator>bwang-tecoustics</dc:creator>
      <dc:date>2017-10-26T12:57:35Z</dc:date>
    </item>
    <item>
      <title>Re: Polyline3d.InsertVertexAt crashes Program</title>
      <link>https://forums.autodesk.com/t5/net-forum/polyline3d-insertvertexat-crashes-program/m-p/7494107#M29174</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3118683"&gt;@bwang-tecoustics&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;Interesting. Your code just works the same way as mine. If I change your code "oEnt.InsertVertexAt(oVt.ObjectId, nVt);" to "oEnt.InsertVertexAt(oVt, nVt);", my AutoCAD crashes. So, there is a problem with the InsertVertexAt(Polyline3dVertex3d, Polyline3dVertex3d) method. I'll just use the InsertVertexAt(ObjectId, Polyline3dVertex3d) method then.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;The version of InsertVertexAt() that takes a PolylineVertex3d as the first argument is only for use on new polylines that haven't been added to the database yet.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2017 16:18:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/polyline3d-insertvertexat-crashes-program/m-p/7494107#M29174</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2017-10-26T16:18:21Z</dc:date>
    </item>
    <item>
      <title>Re: Polyline3d.InsertVertexAt crashes Program</title>
      <link>https://forums.autodesk.com/t5/net-forum/polyline3d-insertvertexat-crashes-program/m-p/12148355#M29175</link>
      <description>&lt;P&gt;This article was from 5 years ago I'm not sure if you're still reading it. (I hope can be useful to someone)&lt;BR /&gt;I use AutoCAD 2023. Even when I use the new Polyline, I get a crash.&lt;BR /&gt;I have realized that the vertex of the polyline is not allowed to open when calling InsertVertexAt() function.&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;I succeeded (didn't get any errors) with this code&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;[CommandMethod("Test")]
public void Test()
{
    var ver3d1 = new PolylineVertex3d(Point3d.Origin);
    var ver3d2 = new PolylineVertex3d(new Point3d(1, 1, 0));
    var ver3d3 = new PolylineVertex3d(new Point3d(2, 1, 0));
    var ver3d4 = new PolylineVertex3d(new Point3d(2, 2, 0));

    var db = HostApplicationServices.WorkingDatabase;
    using (var tr = db.TransactionManager.StartTransaction())
    using (var poly = new Polyline3d())
    {
        var btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
        var polId = btr.AppendEntity(poly);
        tr.AddNewlyCreatedDBObject(poly, true);
        poly.AppendVertex(ver3d1);
        poly.AppendVertex(ver3d2);
        poly.AppendVertex(ver3d3);

        ver3d3.Dispose();  // AutoCAD will crashes if ver3d3 opened
        poly.InsertVertexAt(ver3d3, ver3d4);  // Vertex ver3d4 is added before vertex ver3d3.
        tr.Commit();
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2023 03:57:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/polyline3d-insertvertexat-crashes-program/m-p/12148355#M29175</guid>
      <dc:creator>smx_khang</dc:creator>
      <dc:date>2023-08-04T03:57:28Z</dc:date>
    </item>
    <item>
      <title>Re: Polyline3d.InsertVertexAt crashes Program</title>
      <link>https://forums.autodesk.com/t5/net-forum/polyline3d-insertvertexat-crashes-program/m-p/12148393#M29176</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/13714541"&gt;@smx_khang&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Comment out this line , or remove it&lt;/P&gt;&lt;PRE&gt;ver3d3.Dispose();  // AutoCAD will crashes if ver3d3 opened&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Move these lines down so they are just before the &lt;EM&gt;tr.commit; &lt;/EM&gt;statement&lt;/P&gt;&lt;PRE&gt;        var btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
        var polId = btr.AppendEntity(poly);
        tr.AddNewlyCreatedDBObject(poly, true);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Looking at the code logic, I can't understand why you are even using the statement :&lt;/P&gt;&lt;PRE&gt;poly.InsertVertexAt(ver3d3, ver3d4);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;. . . unless you just wanted to test what the statement does&amp;nbsp; . . in which case a more realistic test would have been to make two seperate methods, one to make the poly, another to select and insert the new vertex , perhaps ??&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2023 04:35:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/polyline3d-insertvertexat-crashes-program/m-p/12148393#M29176</guid>
      <dc:creator>kerry_w_brown</dc:creator>
      <dc:date>2023-08-04T04:35:57Z</dc:date>
    </item>
    <item>
      <title>Re: Polyline3d.InsertVertexAt crashes Program</title>
      <link>https://forums.autodesk.com/t5/net-forum/polyline3d-insertvertexat-crashes-program/m-p/12148594#M29177</link>
      <description>&lt;P&gt;Sorry for the confusing explanation above, &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/529262"&gt;@kerry_w_brown&lt;/a&gt;&amp;nbsp;.&lt;BR /&gt;I was just trying to point out that in certain cases Dispose() is necessary.&lt;/P&gt;&lt;P&gt;Here is a more realistic example of adding a vertex to a polyline. In this case, I need to open Vertex to do some operations on it before adding a vertex to the polyline. If not call Dispose(), AutoCAD will crash.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;[CommandMethod("TEST")]
public void test()
{
    var res = Application.DocumentManager.MdiActiveDocument.Editor.GetEntity("Select polyline");
    if (res.Status != Autodesk.AutoCAD.EditorInput.PromptStatus.OK)
        return;

    using (var tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
    {
        var newVertex = new PolylineVertex3d(new Point3d(2, 1, 0));
        var poly = tr.GetObject(res.ObjectId, OpenMode.ForWrite) as Polyline3d;

        var pos = poly.GetEnumerator();     // I want to loop thrown all vertices of polyline
        pos.MoveNext(); pos.MoveNext();     // Goto 2nd vertex
        var verid = (ObjectId)pos.Current;  // Get its ID

        var pv3d = verid.GetObject(OpenMode.ForWrite) as PolylineVertex3d;

        // Do something with pv3d....

        // If you don't dispose PolylineVertex3d before attempt to passing it into InsertVertexAt,
        // application will crash. (Or else you should probably use InsertVertexAt(ObjectId, PolylineVertex3d) ). 
        pv3d.Dispose();

        // Safely insert vertex.
        poly.InsertVertexAt(pv3d, newVertex);

        tr.Commit();
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2023 07:13:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/polyline3d-insertvertexat-crashes-program/m-p/12148594#M29177</guid>
      <dc:creator>smx_khang</dc:creator>
      <dc:date>2023-08-04T07:13:09Z</dc:date>
    </item>
  </channel>
</rss>

