Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Can't get OnExecute event to fire for my add-in

8 REPLIES 8
Reply
Message 1 of 9
imvu
1483 Views, 8 Replies

Can't get OnExecute event to fire for my add-in

I'm new to Inventor and Inventor plug-ins, but I'm an experienced C++ add-in developer for 3ds Max, and I'm also an experienced C# developer. I'm using Visual Studio Pro 2012 with C# as my development language.

 

I've created a project using the project template, updated the manifest and addin files as appropriate, and made Inventor recognize and load my add-in. I can add a button definition, and add that button to a new panel in a ribbon, and it shows up. However, even though I assign a new delegate to the OnExecute event on the button definition, clicking my button does not call my handling function. I'm sure it's something simple I'm doing wrong, but I've read the documentation and sample code and threads on this forum, and can't figure out what it is.

 

If someone could help me out with this, I'd really appreciate it, because I don't even know how to debug this problem 😞 I attached the entire StandardAddInServer.cs file to this message, but here's the bit that I think matters:

 

 

        public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime)
        {
            m_inventorApplication = addInSiteObject.Application;

            if (firstTime)
            {
                var assemblyRibbon = m_inventorApplication.UserInterfaceManager.Ribbons["Assembly"];
                var inspectTab = assemblyRibbon.RibbonTabs["id_TabInspect"];
                var exportPanel = inspectTab.RibbonPanels.Add("Export", "ToolsTabExportPanel", "SketchExportSVG");
                var bitmap = new System.Drawing.Bitmap(GetType(), "ExportIcon.bmp");
                var exportCommand = m_inventorApplication.CommandManager.ControlDefinitions.AddButtonDefinition(
                        "Sketches to SVG", "SketchExportSVG", CommandTypesEnum.kQueryOnlyCmdType, 
                        "6ab42c21-d44d-4b7b-b18b-f50212ae07eb", "Export sketches as SVG",
                        "Export sketches as SVG");
                exportCommand.OnExecute += exportCommand_OnExecute;
                exportCommand.Enabled = true;
                exportPanel.CommandControls.AddButton(exportCommand);
            }
        }

        void exportCommand_OnExecute(NameValueMap Context)
        {
            m_inventorApplication.ErrorManager.AddMessage("Hello, world!", false);
            m_inventorApplication.ErrorManager.Show("Results", true, false);
        }

 

8 REPLIES 8
Message 2 of 9
imvu
in reply to: imvu

Apologies, I'm new to Inventor development.

Is there something else I can or need to post for anyone to understand this question?

Also, we have a media & entertainment ADN subscription (ADN Sparks); can I ask a question like this there or does that require a separate subscription?

 

Message 3 of 9
xiaodong_liang
in reply to: imvu

Hi,

 

I did not try, but the code looks OK. I suggest you compare it with the SDK samples

\SDK\DeveloperTools\Samples\VCSharp.NET\AddIns which you missed.

 

In addition, it will be more helpful with a buidable sample, instead of code snippet because it does not tell the context to reproduce the problem.

Message 4 of 9
imvu
in reply to: xiaodong_liang

Thanks for trying to help!

 

I actually had compared to the examples in the C# folder, and I don't see anything I do very differently from those. However, as my use case is slightly different, it doesn't match 100% to the way those examples are broken into several parts -- my use case looks more like the simple VB ribbon button sample.

 

Second, I attached my entire project and solution to the post as a ZIP file. Is there anything else you need to be able to test this out that I'm missing?

Message 5 of 9
xiaodong_liang
in reply to: imvu

I found you defined the button definition as a local variable in Activate. Please try to defin it as a global variable in class StandardAddInServer. I think this is why it failed to connect to the event.

Message 6 of 9
imvu
in reply to: imvu

Thanks for the suggeston. I will try it, but I don't quite understand why it would matter.

Either the button definition is a value type, in which case it is copied wherever it's needed, or it's a reference type, in which case it will go away only when there is no reference to it.

Given that it shows up in the toolbar, the application has to have a reference to it.

I will report back how it goes.

 

Message 7 of 9
xiaodong_liang
in reply to: imvu

In the meantime, I did a test at my side. It works well after I put the defintion to the level of class.

 

[GuidAttribute("6ab42c21-d44d-4b7b-b18b-f50212ae07eb")]
public class StandardAddInServer : Inventor.ApplicationAddInServer
{

private Inventor.Application m_inventorApplication;
ButtonDefinition exportCommand;

 

 

Message 8 of 9
Maarten65
in reply to: xiaodong_liang

I am looking for a way to translate an Inventor drawing directly to a SVG file. Did you finally manage to create your tool? If so are you willing to share this with us? 

Best regards,

 

Maarten Weers
Technical Specialist CAD - EMEA
Parker Hannifin
Oldenzaal - The Netherlands
-------------------------------------------------------------------------------------------
Inventor Pro 2019 - Vault Professional 2019 - Windows 10 64 bit -
Message 9 of 9

This works, but I don't understand why. Can someone explain?

I had a similar problem when I created my first add-in (different from the one I tested this on). I spent days troubleshooting it and I never figured out why it didn't work. I'm thinking it might have had something to do with this.

 

Edit: I remember when I was creating event handlers in VBA macros, I believe I found that the ApplicationEvents variable also had to be a class variable. Is this an Inventor thing?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report