Message 1 of 4

Not applicable
07-05-2021
08:24 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I been working on a C# addin for Inventor 2019. This addin creates a toolbar, which works, that has a single button. After registering a handler to the button, nothing happens when I click the button. Interestingly if I manually execute the button, that does what it should.
Note that I have generalized the code to remove certain information (ex. ClassToOpen is not the actual class name).
Any help is greatly appreciated, thanks.
public void Activate(ApplicationAddInSite addInSiteObject, bool firstTime) {
// General addin stuff
Application Inventor = addInSiteObject.Application;
var guid = $"{{{GuidAttribute.Value}}}"; // This is the GUID that is on the addin server attribute
// Button creation
ButtonDefinition command0 = Inventor.CommandManager.ControlDefinitions.AddButtonDefinition("Button 1", nameof(ClassToOpen), CommandTypesEnum.kFilePropertyEditCmdType, guid, "Display dialog", "Display dialog", PictureConverter.GetPicture(Properties.Resources.toolbar_buttons_16x16), PictureConverter.GetPicture(Properties.Resources.toolbar_buttons_24x24));
Command0_EventHandler = new ButtonDefinitionSink_OnExecuteEventHandler(Command0_OnExecute);
command0.OnExecute += Command0_EventHandler;
// This works, but clicking the button does not
command0.Execute();
}
private void Command0_OnExecute(NameValueMap Context) => ClassToOpen.OpenDialog();
private ButtonDefinitionSink_OnExecuteEventHandler Command0_EventHandler;
Solved! Go to Solution.