<?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: Error Plugin on loadong Autocad in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/error-plugin-on-loadong-autocad/m-p/12875677#M3413</link>
    <description>&lt;P&gt;I don't have Winows 7, I'm just runnig code in the &lt;SPAN&gt;debugger&amp;nbsp;&lt;/SPAN&gt;with vs 2019 and win 10 without any error.&lt;/P&gt;</description>
    <pubDate>Wed, 03 Jul 2024 09:39:19 GMT</pubDate>
    <dc:creator>bahman.jf.68</dc:creator>
    <dc:date>2024-07-03T09:39:19Z</dc:date>
    <item>
      <title>Error Plugin on loadong Autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/error-plugin-on-loadong-autocad/m-p/12873507#M3411</link>
      <description>&lt;P&gt;Hello everyone,&amp;nbsp;&lt;BR /&gt;I have written a plugin in C# .Net for Autocad, it works well in systems with Windows 10, but it gives this error in Windows 7 :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot (1204).png" style="width: 379px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1382336i3EE2DD0F40C0C469/image-dimensions/379x276?v=v2" width="379" height="276" role="button" title="Screenshot (1204).png" alt="Screenshot (1204).png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The codes :&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;public class EICommands : IExtensionApplication
    {
     public void createRibbon()
        {
                RibbonControl ribbon = ComponentManager.Ribbon;
                RibbonTab rtab = new RibbonTab();
                rtab = new RibbonTab();
                rtab.Title = "MyPlugin";
                rtab.Id = "Testing";
                //Add the Tab
                ribbon.Tabs.Add(rtab);

                RibbonPanelSource rps = new RibbonPanelSource();
                rps.Title = "Test";
                RibbonPanel rp = new RibbonPanel();
                rp.Source = rps;
                rtab.Panels.Add(rp);

                RibbonButton btn1 = new RibbonButton();
                btn1.Text = "Button1";
                btn1.CommandParameter = "_tspp ";
                btn1.Id = "TOGGLE1";
                btn1.Text = "topo";
                btn1.ShowText = true;
                btn1.ShowImage = true;
                btn1.Image = LoadImage(Properties.Resources.topo);
                btn1.LargeImage = LoadImage(Properties.Resources.topo);
                btn1.Orientation = 
                System.Windows.Controls.Orientation.Vertical;
                btn1.Size = RibbonItemSize.Large;
                btn1.CommandHandler = new RibbonCommandHandler();
                rps.Items.Add(btn1);
                rps.Items.Add(new RibbonSeparator());
      }

      public class RibbonCommandHandler : System.Windows.Input.ICommand
        {

            public bool CanExecute(object parameter)
            {
                return true;
            }

            public event EventHandler CanExecuteChanged;

            public void Execute(object parameter)
            {
                RibbonButton btn = parameter as RibbonButton;
                if (btn != null)
                {
                    Document dwg = 
         Autodesk.AutoCAD.ApplicationServices.Application.
                        DocumentManager.MdiActiveDocument;

                    dwg.SendStringToExecute((string)btn.CommandParameter, 
        true, false, true);
                }
            }
        }
       void IExtensionApplication.Initialize()
        {
             Application.Idle += new EventHandler(Application_Idle);
        }

        void IExtensionApplication.Terminate()
        {
            // Do plug-in application clean up here
        }

        void Application_Idle(object sender, EventArgs e)
        {

            Application.Idle -= Application_Idle;

            EICommands cmd = new EICommands();
            cmd.createRibbon();

        }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have written it in :&lt;BR /&gt;Visual studio 2019&lt;BR /&gt;Autocad 2017 api&lt;BR /&gt;.Net Framework 4.5&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Target system :&lt;BR /&gt;Windows 7 64 bit&lt;BR /&gt;Autocad 2017&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2024 11:21:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/error-plugin-on-loadong-autocad/m-p/12873507#M3411</guid>
      <dc:creator>bahman.jf.68</dc:creator>
      <dc:date>2024-07-02T11:21:57Z</dc:date>
    </item>
    <item>
      <title>Re: Error Plugin on loadong Autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/error-plugin-on-loadong-autocad/m-p/12873963#M3412</link>
      <description>&lt;P&gt;You need to run your code in the debugger to find out on what line the exception was thrown.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2024 14:31:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/error-plugin-on-loadong-autocad/m-p/12873963#M3412</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2024-07-02T14:31:18Z</dc:date>
    </item>
    <item>
      <title>Re: Error Plugin on loadong Autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/error-plugin-on-loadong-autocad/m-p/12875677#M3413</link>
      <description>&lt;P&gt;I don't have Winows 7, I'm just runnig code in the &lt;SPAN&gt;debugger&amp;nbsp;&lt;/SPAN&gt;with vs 2019 and win 10 without any error.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jul 2024 09:39:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/error-plugin-on-loadong-autocad/m-p/12875677#M3413</guid>
      <dc:creator>bahman.jf.68</dc:creator>
      <dc:date>2024-07-03T09:39:19Z</dc:date>
    </item>
    <item>
      <title>Re: Error Plugin on loadong Autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/error-plugin-on-loadong-autocad/m-p/12879016#M3414</link>
      <description>&lt;P&gt;Any help !&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2024 19:56:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/error-plugin-on-loadong-autocad/m-p/12879016#M3414</guid>
      <dc:creator>bahman.jf.68</dc:creator>
      <dc:date>2024-07-04T19:56:10Z</dc:date>
    </item>
    <item>
      <title>Re: Error Plugin on loadong Autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/error-plugin-on-loadong-autocad/m-p/12879117#M3415</link>
      <description>&lt;P&gt;There is more info in the exception text.&amp;nbsp; Maybe a line number?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2024 21:28:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/error-plugin-on-loadong-autocad/m-p/12879117#M3415</guid>
      <dc:creator>fieldguy</dc:creator>
      <dc:date>2024-07-04T21:28:24Z</dc:date>
    </item>
    <item>
      <title>Re: Error Plugin on loadong Autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/error-plugin-on-loadong-autocad/m-p/12880379#M3416</link>
      <description>&lt;P&gt;The error is to create ribbon function on loading DLL, I suggest that DLL cann't access to RibbonControl so that it gives Null.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jul 2024 15:24:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/error-plugin-on-loadong-autocad/m-p/12880379#M3416</guid>
      <dc:creator>bahman.jf.68</dc:creator>
      <dc:date>2024-07-05T15:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: Error Plugin on loadong Autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/error-plugin-on-loadong-autocad/m-p/12880508#M3417</link>
      <description>&lt;P&gt;Since you do not have Window 7 to run debugging, you may have to let your user know that your app does not support Window 7, though it may work in some cases&lt;span class="lia-unicode-emoji" title=":grinning_face_with_sweat:"&gt;😅&lt;/span&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, if I have to guess, then, it may be possible while the first Idle event fires during AutoCAD startup, the ribbon control may still not possible for whatever reason(s).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, to make your code bullet-proof, after the first line of code&lt;/P&gt;
&lt;PRE class="lia-code-sample line-numbers language-csharp" tabindex="0"&gt;&lt;CODE&gt;RibbonControl ribbon = ComponentManager.Ribbon;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you should test if the RibbonControl is null:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if (ribbon!=null)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; // rest of the code for creating your custom ribbon item&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or, at least you could/should place the custom ribbon item creation code in try...catch... block.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the ribbonControl is still null in the first Idle event handler, you may try to use a timer to wait a few seconds and test if AutoCAD is idle then try add custom ribbon again.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jul 2024 15:54:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/error-plugin-on-loadong-autocad/m-p/12880508#M3417</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2024-07-05T15:54:19Z</dc:date>
    </item>
    <item>
      <title>Re: Error Plugin on loadong Autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/error-plugin-on-loadong-autocad/m-p/12880823#M3418</link>
      <description>&lt;P&gt;Instead of kludgy workarounds like timers, etc., you can try using &lt;A href="https://github.com/ActivistInvestor/AcMgdLib/tree/main/AcMgdLib/Ribbon" target="_blank" rel="noopener"&gt;RibbonEventManager&lt;/A&gt; to deal with the problem, as that's what it was created for. If for example, your user has closed the ribbon, the next time AutoCAD starts, there will be no ribbon until the user issues the RIBBON command to show it. Your code is supposed to be prepared to deal with that situation (which RibbonEventManager does).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2024 14:46:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/error-plugin-on-loadong-autocad/m-p/12880823#M3418</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2024-07-15T14:46:21Z</dc:date>
    </item>
    <item>
      <title>Re: Error Plugin on loadong Autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/error-plugin-on-loadong-autocad/m-p/12883195#M3419</link>
      <description>&lt;P&gt;Heads Up:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;RibbonEventManager was just updated to address an issue related to the use of async/await in AutoCAD (the issue affects &lt;EM&gt;any and all use of async/await in AutoCAD&lt;/EM&gt;). If code following a call to &lt;STRONG&gt;await&lt;/STRONG&gt; throws an exception that is not handled locally, it will terminate AutoCAD.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;static async void SomeAsyncMethod()
{
    await SomeAwaitableMethod();
    throw new NotSupportedException();  // terminates AutoCAD
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code was rolled-back to use DocumentCollection.ExecuteInApplicationContext(), (which is just a fancy wrapper for a handler of the Application.Idle event).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone that may be using an earlier version of RibbonEventManager, should update to the &lt;A href="https://github.com/ActivistInvestor/AcMgdUtility/blob/main/RibbonEventManager/RibbonEventManager.cs" target="_blank" rel="noopener"&gt;latest commit&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2024 02:02:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/error-plugin-on-loadong-autocad/m-p/12883195#M3419</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2024-07-08T02:02:17Z</dc:date>
    </item>
  </channel>
</rss>

