<?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: ExecuteCommand is now obsolete (C#) in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/executecommand-is-now-obsolete-c/m-p/10697710#M130255</link>
    <description>&lt;P&gt;Thanks for that, I've got a bit further along, but my plugin is not loaded because of my call to&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;            stdole.IPictureDisp okIconStandard = PictureDispConverter.ToIPictureDisp(new System.Drawing.Icon("PluginIcon.ico", new System.Drawing.Size(16, 16)));
            stdole.IPictureDisp okIconLarge = PictureDispConverter.ToIPictureDisp(new System.Drawing.Icon("PluginIcon.ico", new System.Drawing.Size(32, 32)));
#if false 
            m_sampleButton = cmdMgr.ControlDefinitions.AddButtonDefinition("Command 1",
                                                                            "Command 1",
                                                                            CommandTypesEnum.kFilePropertyEditCmdType,
                                                                            Guid.NewGuid().ToString(),
                                                                            "Command 1 description",
                                                                            "Command 1 Tooltip",
                                                                            okIconStandard,okIconLarge);

#endif &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;AddButtonDefinition. If I don't make that call the plugin gets loaded.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We really need a working wizard for all this stuff!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 19 Oct 2021 08:06:52 GMT</pubDate>
    <dc:creator>oransen</dc:creator>
    <dc:date>2021-10-19T08:06:52Z</dc:date>
    <item>
      <title>ExecuteCommand is now obsolete (C#)</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/executecommand-is-now-obsolete-c/m-p/10695730#M130211</link>
      <description>&lt;P&gt;I've been looking at InventorAddIn1, and at a certain point I read:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;public void ExecuteCommand(int commandID)
{
    // Note:this method is now obsolete, you should use the 
    // ControlDefinition functionality for implementing commands.
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But for the life of me I can't find any C# examples of how to add a command (and presumably a button) using ControlDefinitions. I've found fragments, but I get lost in the disjointedness of it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far I've got to this...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;        public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime)
        {
            // This method is called by Inventor when it loads the addin.
            // The AddInSiteObject provides access to the Inventor Application object.
            // The FirstTime flag indicates if the addin is loaded for the first time.

            // Initialize AddIn members.
            m_inventorApplication = addInSiteObject.Application;

            var cmdMgr = m_inventorApplication.CommandManager;
 
            Icon BigIcon = new Icon("Icon1.ico");
            Icon SmallIcon = new Icon("Icon1.ico");

            m_sampleButton  = cmdMgr.ControlDefinitions.AddButtonDefinition("Command 1",
                                                                            "Command 1",
                                                                            CommandTypesEnum.kFilePropertyEditCmdType,
                                                                            Guid.NewGuid().ToString(),
                                                                            "Command 1 description",
                                                                            "Command 1 Tooltip",
                                                                            BigIcon, SmallIcon);

            // TODO: Add ApplicationAddInServer.Activate implementation.
            MessageBox.Show ("Hello from icony");
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...and presumably there is a way of adding the button to the ribbon and a way of associating the button to a custom command (using the mysterious ControlDefinition method).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So,&lt;/P&gt;&lt;P&gt;Q1) how do I add a button to the ribbon?&lt;/P&gt;&lt;P&gt;Q2) how to I associate my command to the button?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Help!&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;&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 13:29:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/executecommand-is-now-obsolete-c/m-p/10695730#M130211</guid>
      <dc:creator>oransen</dc:creator>
      <dc:date>2021-10-18T13:29:11Z</dc:date>
    </item>
    <item>
      <title>Re: ExecuteCommand is now obsolete (C#)</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/executecommand-is-now-obsolete-c/m-p/10696709#M130240</link>
      <description>&lt;P&gt;Something like this?&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime)
{
    var cmdMgr = m_inventorApplication.CommandManager;

    Icon BigIcon = new Icon("Icon1.ico");
    Icon SmallIcon = new Icon("Icon1.ico");

    ButtonDefinition buttonDef = cmdMgr.ControlDefinitions.AddButtonDefinition(
                            "Command 1",
                            "Command 1",
                            CommandTypesEnum.kFilePropertyEditCmdType,
                            Guid.NewGuid().ToString(),
                            "Command 1 description",
                            "Command 1 Tooltip",
                            BigIcon, SmallIcon);

    buttonDef.OnExecute += ButtonDef_OnExecute;


    Ribbon partRibbon = m_inventorApplication.UserInterfaceManager.Ribbons["Part"]; 
    RibbonTab toolsTab = partRibbon.RibbonTabs["id_TabTools"];
    RibbonPanel customPanel = toolsTab.RibbonPanels.Add("Sample", "MysSample", Guid.NewGuid().ToString());
    customPanel.CommandControls.AddButton(buttonDef);

}

private void ButtonDef_OnExecute(NameValueMap Context)
{
    m_inventorApplication.CommandManager.ControlDefinitions["AppZoomallCmd"].Execute();
}&lt;/LI-CODE&gt;&lt;P&gt;somethin&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 20:20:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/executecommand-is-now-obsolete-c/m-p/10696709#M130240</guid>
      <dc:creator>JelteDeJong</dc:creator>
      <dc:date>2021-10-18T20:20:36Z</dc:date>
    </item>
    <item>
      <title>Re: ExecuteCommand is now obsolete (C#)</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/executecommand-is-now-obsolete-c/m-p/10697710#M130255</link>
      <description>&lt;P&gt;Thanks for that, I've got a bit further along, but my plugin is not loaded because of my call to&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;            stdole.IPictureDisp okIconStandard = PictureDispConverter.ToIPictureDisp(new System.Drawing.Icon("PluginIcon.ico", new System.Drawing.Size(16, 16)));
            stdole.IPictureDisp okIconLarge = PictureDispConverter.ToIPictureDisp(new System.Drawing.Icon("PluginIcon.ico", new System.Drawing.Size(32, 32)));
#if false 
            m_sampleButton = cmdMgr.ControlDefinitions.AddButtonDefinition("Command 1",
                                                                            "Command 1",
                                                                            CommandTypesEnum.kFilePropertyEditCmdType,
                                                                            Guid.NewGuid().ToString(),
                                                                            "Command 1 description",
                                                                            "Command 1 Tooltip",
                                                                            okIconStandard,okIconLarge);

#endif &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;AddButtonDefinition. If I don't make that call the plugin gets loaded.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We really need a working wizard for all this stuff!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Oct 2021 08:06:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/executecommand-is-now-obsolete-c/m-p/10697710#M130255</guid>
      <dc:creator>oransen</dc:creator>
      <dc:date>2021-10-19T08:06:52Z</dc:date>
    </item>
    <item>
      <title>Re: ExecuteCommand is now obsolete (C#)</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/executecommand-is-now-obsolete-c/m-p/10698243#M130270</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5011186"&gt;@JelteDeJong&lt;/a&gt;, again many thanks for your reply, after a bit of juggling I got this to work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;// Adding a button and a command into an Inventor ribbon
// 2021-10-18 : Started

using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Inventor;
using Microsoft.Win32;

namespace InventorAddIn1
{
    /// &amp;lt;summary&amp;gt;
    /// This is the primary AddIn Server class that implements the ApplicationAddInServer interface
    /// that all Inventor AddIns are required to implement. The communication between Inventor and
    /// the AddIn is via the methods on this interface.
    /// &amp;lt;/summary&amp;gt;
    [GuidAttribute("bc7a9e92-f455-431d-9378-c791092de1cc")]
    public class StandardAddInServer : Inventor.ApplicationAddInServer
    {

        #region Data Members

        // Inventor application object...
        private Inventor.Application m_inventorApplication;

        // The button I will add in...
        private ButtonDefinition m_sampleButton = null;

        #endregion

        public StandardAddInServer()
        {
        }

        #region ApplicationAddInServer Members


        // Inventor will call this if it finds a (this) DLL in the appropriate place, for example
        // C:\Users\ofr\AppData\Roaming\Autodesk\ApplicationPlugins\InventorAddIn1\InventorAddIn1.dll
        // We are passed Inventor application which me must hold and cherish...
        public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime)
        {

            // This method is called by Inventor when it loads the addin.
            // The AddInSiteObject provides access to the Inventor Application object.
            // The FirstTime flag indicates if the addin is loaded for the first time.
            m_inventorApplication = addInSiteObject.Application;

            // I use try-catch because Inventor swallows the exceptions silently and does not
            // warn you or the user that anything has gone wrong. The catch will give you a clue
            // if something does go wrong...
            try
            {
                // This was me checking that m_inventorApplication is initialized properly
                MessageBox.Show("locale=" + m_inventorApplication.Locale.ToString()) ;
                var cmdMgr = m_inventorApplication.CommandManager;

                // Create the button (without icons, icons appear to be tricky)...
                m_sampleButton = cmdMgr.ControlDefinitions.AddButtonDefinition("Command 1", // Display name
                                                                               "Command 1", // Internal name
                                                                                CommandTypesEnum.kQueryOnlyCmdType, // No changes, just looking
                                                                                Guid.NewGuid().ToString(), // Invent an id for this command
                                                                                "Command 1 description", 
                                                                                "Command 1 Tooltip"); // shows when mouse hovers

                m_sampleButton.OnExecute += ButtonDef_OnExecute; // Tell the button what it should do when clicked, see function below

#if false
                // If you want show the name of each ribbon....
                foreach (Ribbon r in m_inventorApplication.UserInterfaceManager.Ribbons)
                {
                    MessageBox.Show(r.InternalName);
                }
#endif 

                // Which of these Ribbons (lines) you choose depends on whether you plug in handles Parts or Assemblies...
                // Ribbon TheRibbon = m_inventorApplication.UserInterfaceManager.Ribbons["Part"]; // command active when a part doc is active is open
                Ribbon TheRibbon = m_inventorApplication.UserInterfaceManager.Ribbons["Assembly"]; // command active when an assembly doc is active

#if false
                // If you want show the name of each tab in the ribbon....
                foreach (RibbonTab t in partRibbon.RibbonTabs)
                {
                    MessageBox.Show(t.InternalName);
                }
#endif 

                RibbonTab toolsTab = TheRibbon.RibbonTabs["id_TabTools"]; // tools is present in both parts and assemblies
                // MessageBox.Show ("tools tab internal name = " + toolsTab.InternalName);
                RibbonPanel customPanel = toolsTab.RibbonPanels.Add("Sample", "MysSample", Guid.NewGuid().ToString());
                // MessageBox.Show("Custom panel internal name = " + customPanel.InternalName);

                customPanel.CommandControls.AddButton(m_sampleButton);
            }
            catch (Exception Err)
            {
                MessageBox.Show("Error " + Err.Message);
            }

            MessageBox.Show ("Plugin loaded");
        }


        // This is the function you added to the button a few lines above
        private void ButtonDef_OnExecute(NameValueMap Context)
        {
            // This is a test of calling a standard Inventor command...
            m_inventorApplication.CommandManager.ControlDefinitions["AppZoomallCmd"].Execute();

            // This is my simple test of something I do...
            MessageBox.Show("My Command Called");
        }

        public void Deactivate()
        {
            // This method is called by Inventor when the AddIn is unloaded.
            // The AddIn will be unloaded either manually by the user or
            // when the Inventor session is terminated

            // TODO: Add ApplicationAddInServer.Deactivate implementation

            // Release objects.
            m_inventorApplication = null;

            GC.Collect();
            GC.WaitForPendingFinalizers();
        }

        public void ExecuteCommand(int commandID)
        {
            // Note:this method is now obsolete, you should use the 
            // ControlDefinition functionality for implementing commands.
        }

        public object Automation
        {
            // This property is provided to allow the AddIn to expose an API 
            // of its own to other programs. Typically, this  would be done by
            // implementing the AddIn's API interface in a class and returning 
            // that class object through this property.

            get
            {
                // TODO: Add ApplicationAddInServer.Automation getter implementation
                return null;
            }
        }

#endregion

    }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 19 Oct 2021 12:07:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/executecommand-is-now-obsolete-c/m-p/10698243#M130270</guid>
      <dc:creator>oransen</dc:creator>
      <dc:date>2021-10-19T12:07:24Z</dc:date>
    </item>
  </channel>
</rss>

