C# Toolbar button not working on click

C# Toolbar button not working on click

Anonymous
Not applicable
892 Views
3 Replies
Message 1 of 4

C# Toolbar button not working on click

Anonymous
Not applicable

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;

 

0 Likes
Accepted solutions (1)
893 Views
3 Replies
Replies (3)
Message 2 of 4

bradeneuropeArthur
Mentor
Mentor
Accepted solution

Where have you declared the CommandButton?

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 3 of 4

Anonymous
Not applicable

Aha! That was it, thank you.

 

Updated command0 from my sample to be a private class variable and all is well.

Message 4 of 4

bradeneuropeArthur
Mentor
Mentor

Sometimes things are easy sometimes not.

Good luck further!

@Anonymous 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes