<?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 Create a Polyline with Insertion Point Prompt in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/create-a-polyline-with-insertion-point-prompt/m-p/3369351#M56869</link>
    <description>&lt;P&gt;Hey Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been going through some examples on &lt;A href="http://through-the-interface.typepad.com/" target="_blank"&gt;http://through-the-interface.typepad.com&lt;/A&gt;&amp;nbsp;to create polylines and i've managed to make some code run. One thing that I can't seem to find information on though, is how to use the default AutoCAD command line options in my code. For instance, I would like to be able to prompt the user whether they would like to snap the polyline to an insertion point, everytime they create a new verticie. &amp;nbsp;I'm not sure how to do this, does anyone have an suggestions or experience with this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;Vince&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is some example code from the site that i'm working from:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;namespace MyPlineApp&lt;BR /&gt;{&lt;BR /&gt;public class MyPlineCmds&lt;BR /&gt;{&lt;BR /&gt;[CommandMethod("MYPOLY")]&lt;BR /&gt;public void MyPoly()&lt;BR /&gt;{&lt;BR /&gt;Document doc =&lt;BR /&gt;Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;Database db = doc.Database;&lt;BR /&gt;Editor ed = doc.Editor;&lt;/P&gt;&lt;P&gt;// Get the current color, for our temp graphics&lt;BR /&gt;Color col = doc.Database.Cecolor;&lt;/P&gt;&lt;P&gt;// Create a point collection to store our vertices&lt;BR /&gt;Point3dCollection pts = new Point3dCollection();&lt;/P&gt;&lt;P&gt;// Set up the selection options&lt;BR /&gt;// (used for all vertices)&lt;BR /&gt;PromptPointOptions opt =&lt;BR /&gt;new PromptPointOptions(&lt;BR /&gt;"\nSelect polyline vertex: "&lt;BR /&gt;);&lt;BR /&gt;opt.AllowNone = true;&lt;/P&gt;&lt;P&gt;// Get the start point for the polyline&lt;BR /&gt;PromptPointResult res = ed.GetPoint(opt);&lt;BR /&gt;while (res.Status == PromptStatus.OK)&lt;BR /&gt;{&lt;BR /&gt;// Add the selected point to the list&lt;BR /&gt;pts.Add(res.Value);&lt;/P&gt;&lt;P&gt;// Drag a temp line during selection&lt;BR /&gt;// of subsequent points&lt;BR /&gt;opt.UseBasePoint = true;&lt;BR /&gt;opt.BasePoint = res.Value;&lt;BR /&gt;res = ed.GetPoint(opt);&lt;BR /&gt;if (res.Status == PromptStatus.OK)&lt;BR /&gt;{&lt;BR /&gt;// For each point selected,&lt;BR /&gt;// draw a temporary segment&lt;BR /&gt;ed.DrawVector(&lt;BR /&gt;pts[pts.Count - 1], // start point&lt;BR /&gt;res.Value, // end point&lt;BR /&gt;col.ColorIndex, // current color&lt;BR /&gt;false); // highlighted?&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;if (res.Status == PromptStatus.None)&lt;BR /&gt;{&lt;BR /&gt;// Get the current UCS&lt;BR /&gt;Matrix3d ucs =&lt;BR /&gt;ed.CurrentUserCoordinateSystem;&lt;BR /&gt;Point3d origin = new Point3d(0, 0, 0);&lt;BR /&gt;Vector3d normal = new Vector3d(0, 0, 1);&lt;BR /&gt;normal = normal.TransformBy(ucs);&lt;/P&gt;&lt;P&gt;// Create a temporary plane, to help with calcs&lt;BR /&gt;Plane plane = new Plane(origin, normal);&lt;/P&gt;&lt;P&gt;// Create the polyline, specifying&lt;BR /&gt;// the number of vertices up front&lt;BR /&gt;Polyline pline = new Polyline(pts.Count);&lt;BR /&gt;pline.Normal = normal;&lt;BR /&gt;foreach (Point3d pt in pts)&lt;BR /&gt;{&lt;BR /&gt;Point3d transformedPt = pt.TransformBy(ucs);&lt;BR /&gt;pline.AddVertexAt(pline.NumberOfVertices, plane.ParameterOf(transformedPt),0, 0, 0);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Now let's add the polyline to the modelspace&lt;BR /&gt;Transaction tr =&lt;BR /&gt;db.TransactionManager.StartTransaction();&lt;BR /&gt;using (tr)&lt;BR /&gt;{&lt;BR /&gt;BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);&lt;BR /&gt;BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace],OpenMode.ForWrite);&lt;BR /&gt;ObjectId plineId = btr.AppendEntity(pline);&lt;BR /&gt;tr.AddNewlyCreatedDBObject(pline, true);&lt;BR /&gt;tr.Commit();&lt;BR /&gt;ed.WriteMessage("\nPolyline entity is: " + plineId.ToString());&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;// Clear the temp graphics (polyline should be in&lt;BR /&gt;// the same location, if selection was not cancelled)&lt;BR /&gt;// We could "redraw" instead of "regen" here&lt;BR /&gt;ed.Regen();&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;</description>
    <pubDate>Tue, 13 Mar 2012 17:34:52 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2012-03-13T17:34:52Z</dc:date>
    <item>
      <title>Create a Polyline with Insertion Point Prompt</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-a-polyline-with-insertion-point-prompt/m-p/3369351#M56869</link>
      <description>&lt;P&gt;Hey Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been going through some examples on &lt;A href="http://through-the-interface.typepad.com/" target="_blank"&gt;http://through-the-interface.typepad.com&lt;/A&gt;&amp;nbsp;to create polylines and i've managed to make some code run. One thing that I can't seem to find information on though, is how to use the default AutoCAD command line options in my code. For instance, I would like to be able to prompt the user whether they would like to snap the polyline to an insertion point, everytime they create a new verticie. &amp;nbsp;I'm not sure how to do this, does anyone have an suggestions or experience with this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;Vince&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is some example code from the site that i'm working from:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;namespace MyPlineApp&lt;BR /&gt;{&lt;BR /&gt;public class MyPlineCmds&lt;BR /&gt;{&lt;BR /&gt;[CommandMethod("MYPOLY")]&lt;BR /&gt;public void MyPoly()&lt;BR /&gt;{&lt;BR /&gt;Document doc =&lt;BR /&gt;Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;Database db = doc.Database;&lt;BR /&gt;Editor ed = doc.Editor;&lt;/P&gt;&lt;P&gt;// Get the current color, for our temp graphics&lt;BR /&gt;Color col = doc.Database.Cecolor;&lt;/P&gt;&lt;P&gt;// Create a point collection to store our vertices&lt;BR /&gt;Point3dCollection pts = new Point3dCollection();&lt;/P&gt;&lt;P&gt;// Set up the selection options&lt;BR /&gt;// (used for all vertices)&lt;BR /&gt;PromptPointOptions opt =&lt;BR /&gt;new PromptPointOptions(&lt;BR /&gt;"\nSelect polyline vertex: "&lt;BR /&gt;);&lt;BR /&gt;opt.AllowNone = true;&lt;/P&gt;&lt;P&gt;// Get the start point for the polyline&lt;BR /&gt;PromptPointResult res = ed.GetPoint(opt);&lt;BR /&gt;while (res.Status == PromptStatus.OK)&lt;BR /&gt;{&lt;BR /&gt;// Add the selected point to the list&lt;BR /&gt;pts.Add(res.Value);&lt;/P&gt;&lt;P&gt;// Drag a temp line during selection&lt;BR /&gt;// of subsequent points&lt;BR /&gt;opt.UseBasePoint = true;&lt;BR /&gt;opt.BasePoint = res.Value;&lt;BR /&gt;res = ed.GetPoint(opt);&lt;BR /&gt;if (res.Status == PromptStatus.OK)&lt;BR /&gt;{&lt;BR /&gt;// For each point selected,&lt;BR /&gt;// draw a temporary segment&lt;BR /&gt;ed.DrawVector(&lt;BR /&gt;pts[pts.Count - 1], // start point&lt;BR /&gt;res.Value, // end point&lt;BR /&gt;col.ColorIndex, // current color&lt;BR /&gt;false); // highlighted?&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;if (res.Status == PromptStatus.None)&lt;BR /&gt;{&lt;BR /&gt;// Get the current UCS&lt;BR /&gt;Matrix3d ucs =&lt;BR /&gt;ed.CurrentUserCoordinateSystem;&lt;BR /&gt;Point3d origin = new Point3d(0, 0, 0);&lt;BR /&gt;Vector3d normal = new Vector3d(0, 0, 1);&lt;BR /&gt;normal = normal.TransformBy(ucs);&lt;/P&gt;&lt;P&gt;// Create a temporary plane, to help with calcs&lt;BR /&gt;Plane plane = new Plane(origin, normal);&lt;/P&gt;&lt;P&gt;// Create the polyline, specifying&lt;BR /&gt;// the number of vertices up front&lt;BR /&gt;Polyline pline = new Polyline(pts.Count);&lt;BR /&gt;pline.Normal = normal;&lt;BR /&gt;foreach (Point3d pt in pts)&lt;BR /&gt;{&lt;BR /&gt;Point3d transformedPt = pt.TransformBy(ucs);&lt;BR /&gt;pline.AddVertexAt(pline.NumberOfVertices, plane.ParameterOf(transformedPt),0, 0, 0);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Now let's add the polyline to the modelspace&lt;BR /&gt;Transaction tr =&lt;BR /&gt;db.TransactionManager.StartTransaction();&lt;BR /&gt;using (tr)&lt;BR /&gt;{&lt;BR /&gt;BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);&lt;BR /&gt;BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace],OpenMode.ForWrite);&lt;BR /&gt;ObjectId plineId = btr.AppendEntity(pline);&lt;BR /&gt;tr.AddNewlyCreatedDBObject(pline, true);&lt;BR /&gt;tr.Commit();&lt;BR /&gt;ed.WriteMessage("\nPolyline entity is: " + plineId.ToString());&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;// Clear the temp graphics (polyline should be in&lt;BR /&gt;// the same location, if selection was not cancelled)&lt;BR /&gt;// We could "redraw" instead of "regen" here&lt;BR /&gt;ed.Regen();&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Tue, 13 Mar 2012 17:34:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-a-polyline-with-insertion-point-prompt/m-p/3369351#M56869</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-03-13T17:34:52Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Polyline with Insertion Point Prompt</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-a-polyline-with-insertion-point-prompt/m-p/3369503#M56870</link>
      <description>&lt;P&gt;You probably want to use Editor.Snap() in conjunction with Editor.GetPoint(). That is, with Editor.getPoint(), user pick a point, which may not be the exact point your code expected, then you call Editor.Snap() with user-picked point as input parameter and with appropriate snap mode, Editor.Snap() then returns a snapped point, based on snap mode.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Mar 2012 18:41:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-a-polyline-with-insertion-point-prompt/m-p/3369503#M56870</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2012-03-13T18:41:04Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Polyline with Insertion Point Prompt</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-a-polyline-with-insertion-point-prompt/m-p/3369529#M56871</link>
      <description>&lt;P&gt;Thanks, that sounds like what i'm looking for. You wouldn't happen to have an example of this in action would you?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Mar 2012 18:56:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-a-polyline-with-insertion-point-prompt/m-p/3369529#M56871</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-03-13T18:56:25Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Polyline with Insertion Point Prompt</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-a-polyline-with-insertion-point-prompt/m-p/3369625#M56872</link>
      <description>&lt;P&gt;OK, here is code sample:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;class MyCommands
    {

        [CommandMethod("MyCmd", CommandFlags.Session)]
        public static void MyCmd()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;

            PromptPointOptions opt = new PromptPointOptions("Pick line at one of its end: ");
            PromptPointResult res = ed.GetPoint(opt);
            if (res.Status == PromptStatus.OK)
            {
                Point3d pt = ed.Snap("ENDP", res.Value);

                ed.WriteMessage("\nPicked point: {0}, {1}, {2}", res.Value.X, res.Value.Y, res.Value.Z);
                ed.WriteMessage("\nSnapped point: {0}, {1}, {2}", pt.X, pt.Y, pt.Z);
            }
        }
    }&lt;/PRE&gt;&lt;P&gt;To try the code, you can draw a line, and then pick anywhere at the line (but not the end), it will get one of the end point, depending on the picked poin is closer to which end.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Other snap mode parameter would be like "NEA", "INS", "INT", "CEN"...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, you need to be careful: user may be very accustomed at using Acad with object snap turned on. In this case, when GetPoint() is called, AutoCAD display auto-snap grip to whatever snap modes that are turned on. But the snap mode in Editor.Snap() method wins. If the snap mode in Editor.Snap() method is different from user sees (AutoCAD object snap prompted snap grip), the result may confuse user to mislead user...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, if you use Editor.Snap() for specific reason, you might as well check if Object SNAP is turned on, if it is, you may want to save the snap mode (system variable OSMODE)&amp;nbsp;in a variable; then turn it off; then after Editor.Snap() call, you restore the object snap mode back to its original mode.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;HTH&lt;/P&gt;</description>
      <pubDate>Tue, 13 Mar 2012 19:46:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-a-polyline-with-insertion-point-prompt/m-p/3369625#M56872</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2012-03-13T19:46:22Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Polyline with Insertion Point Prompt</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-a-polyline-with-insertion-point-prompt/m-p/3373935#M56873</link>
      <description>&lt;P&gt;Thanks for the response and the sample code...it was a good guideline. I found the example of calculating area in the .NET developers handbook and have implemented that. A few questions though are how to get the polyline to remain static until the last point is picked, and how to modify the code so that it continiously requests new points until the user press a certain key or clicks back on the origin point. I'm working on the second part right now and i'm sure it'll go. Any suggestions or assistance would be great though.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;Vince&lt;/P&gt;</description>
      <pubDate>Fri, 16 Mar 2012 12:27:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-a-polyline-with-insertion-point-prompt/m-p/3373935#M56873</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-03-16T12:27:05Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Polyline with Insertion Point Prompt</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-a-polyline-with-insertion-point-prompt/m-p/3374849#M56874</link>
      <description>&lt;P&gt;If you want to continuously let user to pick point to build up your polyline (similar as "POLYLINE" command in ACAD), you begin with Editor.GetPoint() and go into t loop. Kean Wamsley has posted an article on creating a polyline interactively a few year ago:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://through-the-interface.typepad.com/through_the_interface/2006/11/controlling_int.html" target="_blank"&gt;http://through-the-interface.typepad.com/through_the_interface/2006/11/controlling_int.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It might be what you are looking for.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Mar 2012 20:18:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-a-polyline-with-insertion-point-prompt/m-p/3374849#M56874</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2012-03-16T20:18:55Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Polyline with Insertion Point Prompt</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-a-polyline-with-insertion-point-prompt/m-p/3378571#M56875</link>
      <description>&lt;P&gt;Hey,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the tip. That helped immensley.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;Vince&lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2012 19:22:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-a-polyline-with-insertion-point-prompt/m-p/3378571#M56875</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-03-20T19:22:55Z</dc:date>
    </item>
  </channel>
</rss>

