Inventor Customization

Reply
Member
imvu
Posts: 5
Registered: ‎11-05-2012
Message 1 of 7 (513 Views)

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

513 Views, 6 Replies
11-05-2012 01:40 PM

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);
        }

 

Member
imvu
Posts: 5
Registered: ‎11-05-2012
Message 2 of 7 (504 Views)

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

11-06-2012 01:33 PM 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?

 

ADN Support Specialist
xiaodong.liang
Posts: 1,233
Registered: ‎06-12-2011
Message 3 of 7 (488 Views)

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

11-14-2012 06:40 PM 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.



Xiaodong Liang
Developer Technical Services
Autodesk Developer Network

Member
imvu
Posts: 5
Registered: ‎11-05-2012
Message 4 of 7 (482 Views)

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

11-14-2012 07:42 PM 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?

ADN Support Specialist
xiaodong.liang
Posts: 1,233
Registered: ‎06-12-2011
Message 5 of 7 (466 Views)

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

11-21-2012 08:06 PM 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.



Xiaodong Liang
Developer Technical Services
Autodesk Developer Network

Member
imvu
Posts: 5
Registered: ‎11-05-2012
Message 6 of 7 (463 Views)

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

11-21-2012 10:26 PM 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.

 

ADN Support Specialist
xiaodong.liang
Posts: 1,233
Registered: ‎06-12-2011
Message 7 of 7 (458 Views)

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

11-21-2012 11:34 PM 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;

 

 



Xiaodong Liang
Developer Technical Services
Autodesk Developer Network

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube