<?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: How to simulate the Polyline command through code? in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-to-simulate-the-polyline-command-through-code/m-p/12331872#M6871</link>
    <description>&lt;P&gt;I no more have AutoCAD 2014 to test, but this issue is not due to StartUserInteraction because the dialog box hides itself (even if it shows quasi immediately). I suspect the EditorInputExtension.Command method to work slightly differently from the AutoCAD 2015 native one.&lt;/P&gt;
&lt;P&gt;It looks like you have to mimic the _PLINE command with code.&lt;/P&gt;
&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/529262"&gt;@kerry_w_brown&lt;/a&gt; provided you a &lt;A href="https://forums.autodesk.com/t5/net/how-to-simulate-the-polyline-command-through-code/m-p/12326441/highlight/true#M79162" target="_blank" rel="noopener"&gt;link&lt;/A&gt; to a method which can be used to draw a simple polyline (only line segments with no width), Kean Walmsley showed a way to draw a polyline with arc segments with a Jig &lt;A href="https://through-the-interface.typepad.com/through_the_interface/2010/12/jigging-an-autocad-polyline-with-arc-segments-using-net.html" target="_blank" rel="noopener"&gt;here&lt;/A&gt;.&lt;/P&gt;</description>
    <pubDate>Thu, 26 Oct 2023 05:46:34 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2023-10-26T05:46:34Z</dc:date>
    <item>
      <title>How to simulate the Polyline command through code?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-simulate-the-polyline-command-through-code/m-p/12326000#M6859</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I need to implement a command to draw a polyline. I want to click a button in the window, and the window will hide. Then, I can use the mouse to draw the polyline, and when I'm done, the window will reappear.And during the drawing process, I hope to simulate the direct use of the PL (Polyline) command's effect, where a line connecting each selected point to the next one is displayed. This is because I am developing a window feature that requires drawing polylines, but I cannot close the window to use the PL command, as it would prevent me from saving my information.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Oct 2023 03:39:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-simulate-the-polyline-command-through-code/m-p/12326000#M6859</guid>
      <dc:creator>zhengyunyang2019</dc:creator>
      <dc:date>2023-10-24T03:39:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to simulate the Polyline command through code?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-simulate-the-polyline-command-through-code/m-p/12326441#M6860</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/8108635"&gt;@zhengyunyang2019&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Perhaps something like this ( from Gilles ) called from your button_click event handler would suit you.&lt;/P&gt;&lt;P&gt;Simpler than a Jig.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/net/drawing-polyine/m-p/5407101/highlight/true#M42505" target="_blank"&gt;https://forums.autodesk.com/t5/net/drawing-polyine/m-p/5407101/highlight/true#M42505&lt;/A&gt;&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;</description>
      <pubDate>Tue, 24 Oct 2023 07:23:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-simulate-the-polyline-command-through-code/m-p/12326441#M6860</guid>
      <dc:creator>kerry_w_brown</dc:creator>
      <dc:date>2023-10-24T07:23:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to simulate the Polyline command through code?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-simulate-the-polyline-command-through-code/m-p/12326447#M6861</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The simplest way is to call the native "_PLINE" command with &lt;A href="https://help.autodesk.com/view/OARX/2023/ENU/?guid=OARX-ManagedRefGuide-Autodesk_AutoCAD_EditorInput_Editor_Command_params_object__" target="_blank" rel="noopener"&gt;Editor.Command&lt;/A&gt; method.&lt;/P&gt;
&lt;P&gt;Assuming the dialog is shown as modal dialog (i.e. shown with &lt;A href="https://help.autodesk.com/view/OARX/2023/ENU/?guid=OARX-ManagedRefGuide-Autodesk_AutoCAD_ApplicationServices_Application_ShowModalDialog_Form" target="_blank" rel="noopener"&gt;Application.ShowModalDialog&lt;/A&gt; method), you have to use &lt;A href="https://help.autodesk.com/view/OARX/2023/ENU/?guid=OARX-ManagedRefGuide-Autodesk_AutoCAD_EditorInput_Editor_StartUserInteraction_IntPtr" target="_blank" rel="noopener"&gt;Editor.StartUserInteraction&lt;/A&gt; method to automaically hide the dialog during the command.&lt;/P&gt;
&lt;P&gt;You can get the ObjectId of the created polyline by using the &lt;A href="https://help.autodesk.com/view/OARX/2023/ENU/?guid=OARX-ManagedRefGuide-Autodesk_AutoCAD_DatabaseServices_Database_Handseed" target="_blank" rel="noopener"&gt;Database.Handseed&lt;/A&gt; property.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;        private void buttonDrawPolyline_Click(object sender, EventArgs e)
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            long seed = db.Handseed.Value;
            using (ed.StartUserInteraction(this.Handle))
            {
                ed.Command("_pline");
            }
            var plineId = ObjectId.Null;
            for (long i = seed; i &amp;lt; db.Handseed.Value; i++)
            {
                if (db.TryGetObjectId(new Handle(i), out ObjectId id)
                    &amp;amp;&amp;amp; id.ObjectClass.Name == "AcDbPolyline")
                    plineId = id;
            }
            AcAp.ShowAlertDialog($"Polyline ObjectId = {plineId}");
        }&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 24 Oct 2023 07:27:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-simulate-the-polyline-command-through-code/m-p/12326447#M6861</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2023-10-24T07:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to simulate the Polyline command through code?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-simulate-the-polyline-command-through-code/m-p/12329063#M6862</link>
      <description>Thank you for your help. This looks pretty straightforward, but the compiler is indicating that there is no definition for the Command() function in 'ed'. Did I miss any references?</description>
      <pubDate>Wed, 25 Oct 2023 06:31:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-simulate-the-polyline-command-through-code/m-p/12329063#M6862</guid>
      <dc:creator>zhengyunyang2019</dc:creator>
      <dc:date>2023-10-25T06:31:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to simulate the Polyline command through code?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-simulate-the-polyline-command-through-code/m-p/12329071#M6863</link>
      <description>I am developing based on the 2014 version of CAD. Could it be that the difference in versions is why the 2014 version doesn't have this function?</description>
      <pubDate>Wed, 25 Oct 2023 06:37:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-simulate-the-polyline-command-through-code/m-p/12329071#M6863</guid>
      <dc:creator>zhengyunyang2019</dc:creator>
      <dc:date>2023-10-25T06:37:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to simulate the Polyline command through code?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-simulate-the-polyline-command-through-code/m-p/12329104#M6864</link>
      <description>&lt;P&gt;The Editor.Command method came with AutoCAD 2015.&lt;/P&gt;
&lt;P&gt;For prior version, you can try &lt;A href="https://forums.autodesk.com/t5/net/send-command-executes-after-exiting-command-method/m-p/3882952/highlight/true#M34731" target="_blank" rel="noopener"&gt;Tony Tanzillo's wrapper for the undocumented RunCommand method&lt;/A&gt;. You cannot use his wrapper with AutoCAD 2015 and later.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2023 06:56:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-simulate-the-polyline-command-through-code/m-p/12329104#M6864</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2023-10-25T06:56:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to simulate the Polyline command through code?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-simulate-the-polyline-command-through-code/m-p/12329335#M6865</link>
      <description>I used Tony Tanzillo's wrapper and then successfully ran the code you provided. However, it didn't have the expected effect. After clicking the button, the window disappeared and immediately reappeared, so I couldn't draw anything. But after I closed the window again, the polyline command still worked, and I could continue drawing polylines.</description>
      <pubDate>Wed, 25 Oct 2023 08:48:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-simulate-the-polyline-command-through-code/m-p/12329335#M6865</guid>
      <dc:creator>zhengyunyang2019</dc:creator>
      <dc:date>2023-10-25T08:48:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to simulate the Polyline command through code?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-simulate-the-polyline-command-through-code/m-p/12329460#M6866</link>
      <description>&lt;P&gt;Do you show the dialog box with the Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog method?&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2023 09:48:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-simulate-the-polyline-command-through-code/m-p/12329460#M6866</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2023-10-25T09:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to simulate the Polyline command through code?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-simulate-the-polyline-command-through-code/m-p/12329487#M6867</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I tested this code, and no matter what I do inside the curly braces, it just makes the window hide for a moment and then immediately reappear.&lt;/SPAN&gt;&lt;SPAN&gt;Is this related to me using the 2010 version?&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;using (EditorUserInteraction eui = ed.StartUserInteraction(form.Handle))
{
    do anything...
}&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 25 Oct 2023 10:00:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-simulate-the-polyline-command-through-code/m-p/12329487#M6867</guid>
      <dc:creator>zhengyunyang2019</dc:creator>
      <dc:date>2023-10-25T10:00:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to simulate the Polyline command through code?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-simulate-the-polyline-command-through-code/m-p/12329516#M6868</link>
      <description>&lt;P&gt;Difficult to reply viewing so few code. Please, reply to my previous question and/or show the code you use to show/open the dialog box.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Wed, 25 Oct 2023 10:15:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-simulate-the-polyline-command-through-code/m-p/12329516#M6868</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2023-10-25T10:15:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to simulate the Polyline command through code?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-simulate-the-polyline-command-through-code/m-p/12329598#M6869</link>
      <description>&lt;P&gt;Here's a minimalist code sample:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;

using System;
using System.Windows.Forms;

using AcAp = Autodesk.AutoCAD.ApplicationServices.Application;

namespace AddAttributeToBlockSample
{
    public partial class DialogBox : Form
    {
        public DialogBox()
        {
            InitializeComponent();
        }

        private void buttonDrawPolyline_Click(object sender, EventArgs e)
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            long seed = db.Handseed.Value;
            using (ed.StartUserInteraction(this.Handle))
            {
                ed.Command("_pline");
            }
            var plineId = ObjectId.Null;
            for (long i = seed; i &amp;lt; db.Handseed.Value; i++)
            {
                if (db.TryGetObjectId(new Handle(i), out ObjectId id)
                    &amp;amp;&amp;amp; id.ObjectClass.Name == "AcDbPolyline")
                    plineId = id;
            }
            AcAp.ShowAlertDialog($"Polyline ObjectId = {plineId}");
        }
    }

    public class Command
    {
        [CommandMethod("DLG")]
        public static void ShowModalDialog()
        {
            using (var dialog = new DialogBox())
            {
                AcAp.ShowModalDialog(dialog);
            }
        }
    }
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And a screencast:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;div class="lia-vid-container video-embed-center"&gt;&lt;div id="lia-vid-6339834395112w784h540r302" class="lia-video-brightcove-player-container"&gt;&lt;video-js data-video-id="6339834395112" data-account="6057940548001" data-player="default" data-embed="default" class="vjs-fluid" controls="" data-application-id="" style="width: 100%; height: 100%;"&gt;&lt;/video-js&gt;&lt;/div&gt;&lt;script src="https://players.brightcove.net/6057940548001/default_default/index.min.js"&gt;&lt;/script&gt;&lt;script&gt;(function() {  var wrapper = document.getElementById('lia-vid-6339834395112w784h540r302');  var videoEl = wrapper ? wrapper.querySelector('video-js') : null;  if (videoEl) {     if (window.videojs) {       window.videojs(videoEl).ready(function() {         this.on('loadedmetadata', function() {           this.el().querySelectorAll('.vjs-load-progress div[data-start]').forEach(function(bar) {             bar.setAttribute('role', 'presentation');             bar.setAttribute('aria-hidden', 'true');           });         });       });     }  }})();&lt;/script&gt;&lt;a class="video-embed-link" href="https://forums.autodesk.com/t5/video/gallerypage/video-id/6339834395112"&gt;(view in My Videos)&lt;/a&gt;&lt;/div&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2023 11:05:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-simulate-the-polyline-command-through-code/m-p/12329598#M6869</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2023-10-25T11:05:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to simulate the Polyline command through code?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-simulate-the-polyline-command-through-code/m-p/12331563#M6870</link>
      <description>&lt;P&gt;Thank you very much for your help, it's truly crucial to me.&lt;/P&gt;&lt;P&gt;I tested your code and found that it works if the runtime environment is CAD 2020+ VS 2017, yielding results consistent with those in the video you provided,it's great.&lt;/P&gt;&lt;P&gt;Unfortunately, in the case of CAD 2014+VS 2010, the code doesn't work as expected. The window reappears instantly after being hidden and doesn't wait.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The only notable difference between the two environments is that in the 2014 environment, the Editor class does not have a Commad() method.&lt;/P&gt;&lt;P&gt;So, i can only use the EditorInputExtension extension method.&lt;/P&gt;&lt;P&gt;I suspect that there might be some distinction between EditorInputExtension.Commad() and Editor.Commad(), but my knowledge in this area is limited, and I'm unable to resolve this issue. Do you have any suggestions?&lt;/P&gt;&lt;P&gt;I need to use CAD 2014, and in fact, I need to develop plugins for CAD 2014, 2016, and 2020 simultaneously.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or maybe there's a difference in the StartUserInteraction method in different versions?&lt;/P&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;&lt;LI-CODE lang="csharp"&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using System.Reflection;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;

namespace MyTest
{
    static class EditorInputExtension
    {
        public static PromptStatus Command(this Editor editor, params object[] args)
        {
            if (editor == null)
                throw new ArgumentNullException("Editor Extension");
            return runCommand(editor, args);
        }

        static Func&amp;lt;Editor, object[], PromptStatus&amp;gt; runCommand = GenerateRunCommand();

        static Func&amp;lt;Editor, object[], PromptStatus&amp;gt; GenerateRunCommand()
        {
            MethodInfo method =
                typeof(Editor).GetMethod("RunCommand", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
            var instance = Expression.Parameter(typeof(Editor), "instance");
            var args = Expression.Parameter(typeof(object[]), "args");
            return Expression.Lambda&amp;lt;Func&amp;lt;Editor, object[], PromptStatus&amp;gt;&amp;gt;(Expression.Call(instance, method, args), instance, args).Compile();
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 01:58:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-simulate-the-polyline-command-through-code/m-p/12331563#M6870</guid>
      <dc:creator>zhengyunyang2019</dc:creator>
      <dc:date>2023-10-26T01:58:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to simulate the Polyline command through code?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-simulate-the-polyline-command-through-code/m-p/12331872#M6871</link>
      <description>&lt;P&gt;I no more have AutoCAD 2014 to test, but this issue is not due to StartUserInteraction because the dialog box hides itself (even if it shows quasi immediately). I suspect the EditorInputExtension.Command method to work slightly differently from the AutoCAD 2015 native one.&lt;/P&gt;
&lt;P&gt;It looks like you have to mimic the _PLINE command with code.&lt;/P&gt;
&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/529262"&gt;@kerry_w_brown&lt;/a&gt; provided you a &lt;A href="https://forums.autodesk.com/t5/net/how-to-simulate-the-polyline-command-through-code/m-p/12326441/highlight/true#M79162" target="_blank" rel="noopener"&gt;link&lt;/A&gt; to a method which can be used to draw a simple polyline (only line segments with no width), Kean Walmsley showed a way to draw a polyline with arc segments with a Jig &lt;A href="https://through-the-interface.typepad.com/through_the_interface/2010/12/jigging-an-autocad-polyline-with-arc-segments-using-net.html" target="_blank" rel="noopener"&gt;here&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 05:46:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-simulate-the-polyline-command-through-code/m-p/12331872#M6871</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2023-10-26T05:46:34Z</dc:date>
    </item>
  </channel>
</rss>

