<?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: Cancel other command in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/cancel-other-command/m-p/11433148#M11618</link>
    <description>&lt;P&gt;Yes, you assumed correctly about the functions, although I had to add the command flag to all of them. They look like this now:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;/// &amp;lt;summary&amp;gt;
        /// Method to set the grid and snap to 0.01mm.
        /// &amp;lt;/summary&amp;gt;
        [Autodesk.AutoCAD.Runtime.CommandMethod("SNAPUNIT_0_01", CommandFlags.Modal)]
        public void SnapUnit_0_01_Command()
        {
            SetGrid(0.01, 10);
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I tried to add the C^C^ to macro in the AcadToolbar.AddToolbarButton function but AutoCAD replies with:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Unknown command "^C^CSNAPUNIT_10".  Press F1 for help.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the full Initialize function where I am adding the C^C^:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;/// &amp;lt;summary&amp;gt;
        /// AutoCAD calls this method to initialize the extension.
        /// &amp;lt;/summary&amp;gt;
        public void Initialize()
        {
            AcadApplication cadApp = (AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
            AcadToolbar tb = cadApp.MenuGroups.Item(0).Toolbars.Add("GridSnap");
            tb.Dock(Autodesk.AutoCAD.Interop.Common.AcToolbarDockStatus.acToolbarDockLeft);
            
            button0_01mm = tb.AddToolbarButton(0, "0.01", "Sets the Snap/Grid 0.01mm", "^C^CSnapUnit_0_01\n", null);
            button0_05mm = tb.AddToolbarButton(1, "0.05", "Sets the Snap/Grid 0.05mm", "^C^CSnapUnit_0_05\n", null);
            button0_1mm = tb.AddToolbarButton(2, "0.1", "Sets the Snap/Grid 0.1mm", "^C^CSnapUnit_0_1\n", null);
            button0_5mm = tb.AddToolbarButton(3, "0.5", "Sets the Snap/Grid 0.5mm", "^C^CSnapUnit_0_5\n", null);
            button1mm = tb.AddToolbarButton(4, "1", "Sets the Snap/Grid 1mm", "^C^CSnapUnit_1\n", null);
            button5mm = tb.AddToolbarButton(5, "5", "Sets the Snap/Grid 5mm", "^C^CSnapUnit_5\n", null);
            button10mm = tb.AddToolbarButton(6, "10", "Sets the Snap/Grid 10mm", "^C^CSnapUnit_10\n", null);
            button50mm = tb.AddToolbarButton(7, "50", "Sets the Snap/Grid 50mm", "^C^CSnapUnit_50\n", null);
            button100mm = tb.AddToolbarButton(8, "100", "Sets the Snap/Grid 100mm", "^C^CSnapUnit_100\n", null);
            button500mm = tb.AddToolbarButton(9, "500", "Sets the Snap/Grid 500mm", "^C^CSnapUnit_500\n", null);
            button1000mm = tb.AddToolbarButton(10, "1000", "Sets the Snap/Grid 1000mm", "^C^CSnapUnit_1000\n", null);

            SetBitMaps();
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this not the right place to add this?&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;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 20 Sep 2022 11:11:06 GMT</pubDate>
    <dc:creator>dallas.a.adams</dc:creator>
    <dc:date>2022-09-20T11:11:06Z</dc:date>
    <item>
      <title>Cancel other command</title>
      <link>https://forums.autodesk.com/t5/net-forum/cancel-other-command/m-p/11432260#M11616</link>
      <description>&lt;P&gt;I am using a toolbar to display a number of grid sizes that I commonly switch between. I am using this function to loop though all viewports and change the gird size on all of them when the button is pressed on the toolbar.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;void SetGrid(double size, short spacing)
        {
            // Get AutoCAD objects.
            Document doc = Application.DocumentManager.MdiActiveDocument;
            KernelDescriptor kd = new KernelDescriptor();
            Database database = doc.Database;
            Autodesk.AutoCAD.EditorInput.Editor ed = doc.Editor;

            // Get the current CVPORT.
            int currentCVPORT = System.Convert.ToInt32(Application.GetSystemVariable("CVPORT"));

            // Get the other View Ports.
            List&amp;lt;int&amp;gt; viewPortNumbers = new List&amp;lt;int&amp;gt;();
            using (Transaction transaction = database.TransactionManager.StartTransaction())
            {
                SymbolTable symTable = (SymbolTable)transaction.GetObject(database.ViewportTableId, OpenMode.ForRead);
                foreach (ObjectId id in symTable)
                {
                    ViewportTableRecord symbol = (ViewportTableRecord)transaction.GetObject(id, OpenMode.ForWrite);
                    viewPortNumbers.Add(symbol.Number);
                    symbol.GridEnabled = true;
                    symbol.GridIncrements = new Autodesk.AutoCAD.Geometry.Point2d(size, size);
                    symbol.GridMajor = spacing;
                    symbol.SnapIncrements = new Autodesk.AutoCAD.Geometry.Point2d(size, size);
                }
                transaction.Commit();
                doc.Editor.UpdateTiledViewportsFromDatabase();
            }

            // Switch back to original view port.
            Application.SetSystemVariable("CVPORT", currentCVPORT);
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems to work except for if there is another command already in progress. I was wondering how I can cancel the previous command if there is one via .net?&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2022 02:02:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/cancel-other-command/m-p/11432260#M11616</guid>
      <dc:creator>dallas.a.adams</dc:creator>
      <dc:date>2022-09-20T02:02:15Z</dc:date>
    </item>
    <item>
      <title>Re: Cancel other command</title>
      <link>https://forums.autodesk.com/t5/net-forum/cancel-other-command/m-p/11432617#M11617</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming the SetGrid method is called from methods colored with the ComandMethod attribute, if the command macro of the button starts with: ^C^C, it should cancel the running command.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Command:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;[CommandMethod("GRID15", CommandFlags.Modal)]
public void SetGrid_1_5()
{
     SetGrid(1.0, 5);
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro:&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;^C^CGRID15&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 20 Sep 2022 06:53:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/cancel-other-command/m-p/11432617#M11617</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-09-20T06:53:26Z</dc:date>
    </item>
    <item>
      <title>Re: Cancel other command</title>
      <link>https://forums.autodesk.com/t5/net-forum/cancel-other-command/m-p/11433148#M11618</link>
      <description>&lt;P&gt;Yes, you assumed correctly about the functions, although I had to add the command flag to all of them. They look like this now:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;/// &amp;lt;summary&amp;gt;
        /// Method to set the grid and snap to 0.01mm.
        /// &amp;lt;/summary&amp;gt;
        [Autodesk.AutoCAD.Runtime.CommandMethod("SNAPUNIT_0_01", CommandFlags.Modal)]
        public void SnapUnit_0_01_Command()
        {
            SetGrid(0.01, 10);
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I tried to add the C^C^ to macro in the AcadToolbar.AddToolbarButton function but AutoCAD replies with:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Unknown command "^C^CSNAPUNIT_10".  Press F1 for help.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the full Initialize function where I am adding the C^C^:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;/// &amp;lt;summary&amp;gt;
        /// AutoCAD calls this method to initialize the extension.
        /// &amp;lt;/summary&amp;gt;
        public void Initialize()
        {
            AcadApplication cadApp = (AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
            AcadToolbar tb = cadApp.MenuGroups.Item(0).Toolbars.Add("GridSnap");
            tb.Dock(Autodesk.AutoCAD.Interop.Common.AcToolbarDockStatus.acToolbarDockLeft);
            
            button0_01mm = tb.AddToolbarButton(0, "0.01", "Sets the Snap/Grid 0.01mm", "^C^CSnapUnit_0_01\n", null);
            button0_05mm = tb.AddToolbarButton(1, "0.05", "Sets the Snap/Grid 0.05mm", "^C^CSnapUnit_0_05\n", null);
            button0_1mm = tb.AddToolbarButton(2, "0.1", "Sets the Snap/Grid 0.1mm", "^C^CSnapUnit_0_1\n", null);
            button0_5mm = tb.AddToolbarButton(3, "0.5", "Sets the Snap/Grid 0.5mm", "^C^CSnapUnit_0_5\n", null);
            button1mm = tb.AddToolbarButton(4, "1", "Sets the Snap/Grid 1mm", "^C^CSnapUnit_1\n", null);
            button5mm = tb.AddToolbarButton(5, "5", "Sets the Snap/Grid 5mm", "^C^CSnapUnit_5\n", null);
            button10mm = tb.AddToolbarButton(6, "10", "Sets the Snap/Grid 10mm", "^C^CSnapUnit_10\n", null);
            button50mm = tb.AddToolbarButton(7, "50", "Sets the Snap/Grid 50mm", "^C^CSnapUnit_50\n", null);
            button100mm = tb.AddToolbarButton(8, "100", "Sets the Snap/Grid 100mm", "^C^CSnapUnit_100\n", null);
            button500mm = tb.AddToolbarButton(9, "500", "Sets the Snap/Grid 500mm", "^C^CSnapUnit_500\n", null);
            button1000mm = tb.AddToolbarButton(10, "1000", "Sets the Snap/Grid 1000mm", "^C^CSnapUnit_1000\n", null);

            SetBitMaps();
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this not the right place to add this?&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;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2022 11:11:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/cancel-other-command/m-p/11433148#M11618</guid>
      <dc:creator>dallas.a.adams</dc:creator>
      <dc:date>2022-09-20T11:11:06Z</dc:date>
    </item>
    <item>
      <title>Re: Cancel other command</title>
      <link>https://forums.autodesk.com/t5/net-forum/cancel-other-command/m-p/11433228#M11619</link>
      <description>&lt;P&gt;My mistake.&lt;/P&gt;
&lt;P&gt;From the example in the documentation about &lt;A href="https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-A714ECE4-28F8-4101-BE0E-7F93BCCF40C2" target="_blank" rel="noopener"&gt;AddToolbarButton AcitveX method&lt;/A&gt;, the macro string should be:&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;"\u0003\u0003SNAPUNIT_0_01\n"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2022 11:42:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/cancel-other-command/m-p/11433228#M11619</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-09-20T11:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: Cancel other command</title>
      <link>https://forums.autodesk.com/t5/net-forum/cancel-other-command/m-p/11434738#M11620</link>
      <description>&lt;P&gt;Bookmarked !&lt;/P&gt;&lt;P&gt;Thanks Gilles&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2022 23:14:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/cancel-other-command/m-p/11434738#M11620</guid>
      <dc:creator>kerry_w_brown</dc:creator>
      <dc:date>2022-09-20T23:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: Cancel other command</title>
      <link>https://forums.autodesk.com/t5/net-forum/cancel-other-command/m-p/11434898#M11621</link>
      <description>&lt;P&gt;Its working perfectly now. Thank you for your help, it is greatly appreciated. I am now inspired to try a few more functions now.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2022 01:21:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/cancel-other-command/m-p/11434898#M11621</guid>
      <dc:creator>dallas.a.adams</dc:creator>
      <dc:date>2022-09-21T01:21:32Z</dc:date>
    </item>
    <item>
      <title>Re: Cancel other command</title>
      <link>https://forums.autodesk.com/t5/net-forum/cancel-other-command/m-p/11435068#M11622</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;For curiosity . .&amp;nbsp;&lt;/P&gt;&lt;P&gt;What was the purpose of this ??&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;KernelDescriptor kd = new KernelDescriptor();&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;. . . Something to do with hardware Acceleration ??&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2022 03:38:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/cancel-other-command/m-p/11435068#M11622</guid>
      <dc:creator>kerry_w_brown</dc:creator>
      <dc:date>2022-09-21T03:38:16Z</dc:date>
    </item>
    <item>
      <title>Re: Cancel other command</title>
      <link>https://forums.autodesk.com/t5/net-forum/cancel-other-command/m-p/11435120#M11623</link>
      <description>&lt;P&gt;I'm not really sure.&amp;nbsp; Two of those lines at the start of the function are not used at all. Sit down, this might shock you, but I don't know what I'm doing. If I was to hazard a guess it comes from a previous attempt at trying to find the viewport objects. If I remember correctly, you need it to get the Graphics Kernel object to then call other functions like CreateAutoCADDevice and CreateAutoCADModel which is where I was originally thinking I be able to find the Viewports.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But as you can see, I found them in the Viewport table in the database.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2022 04:20:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/cancel-other-command/m-p/11435120#M11623</guid>
      <dc:creator>dallas.a.adams</dc:creator>
      <dc:date>2022-09-21T04:20:06Z</dc:date>
    </item>
  </channel>
</rss>

