How to read addin button in C#



Im havin dificulties to understand way the buttons are interacted in C# API.

So how to read is't state?

What other black magic art has to be preformed before getting buttons active? 


This far I have got it:


public void OnConnectToEnvironment(
string EnvCatID,
object pEnvironmentDispatch,
bool bFirstTime) {

SolidEdgeFramework.CommandBarButton button1;
SolidEdgeFramework.CommandBarButton button2;

Guid envGuid = new Guid(EnvCatID);
SolidEdgeFramework.Environment environment = (SolidEdgeFramework.Environment)pEnvironmentDispatch;

// Allocate room for required arrays for CommandBars.
Array commandNames = Array.CreateInstance(typeof(String), 2);
Array commandIDs = Array.CreateInstance(typeof(int), 2);

// Populate arrays.
commandNames.SetValue("cmdOpen File\n\nOpen File Description\nOpen File", 0);
commandNames.SetValue("cmdButton2\n\nButton2 Description\nButton", 1);

commandIDs.SetValue(101, 0);
commandIDs.SetValue(102, 1);

// Call SetAddInInfo
ref commandNames,
ref commandIDs);

if (bFirstTime)

button1 = m_addin.AddCommandBarButton(EnvCatID, "Buttons", 101);
button1.Style = SolidEdgeFramework.SeButtonStyle.seButtonIconAndCaption;
//button1.Enabled = true;

button2 = m_addin.AddCommandBarButton(EnvCatID, "Buttons", 102);
button2.Style = SolidEdgeFramework.SeButtonStyle.seButtonIconAndCaption;

//button2.Style = SolidEdgeFramework.SeButtonStyle.seButtonIconAndCaption;

SolidEdgeFramework.SeButtonState iin = button1.State;

if (button1.) // How to read?

MessageBox.Show("button pressed");





Re: How to read addin button in C#

The answers to your questions can be found in my RibbonController on GitHub. The key to working with the ribbon controls is to implement the ISEAddInEventsEx interface and sink (attach to) the COM events. This will enable the raising of the OnCommand, OnCommandHelp, OnCommandOnLineHelp & OnCommandUpdateUI events. Note that my RibbonController.Add() is the code that gets executed during the OnConnectToEnvironment() event. Almost anything you could possibly want to setup can be found in that method and it handles varying version of Solid Edge. For example, the SetAddInInfoEx2() call that I make is for ST7 or higher whereas my SetAddInInfoEx() call that I make is for ST7 or lower. The difference being is that SetAddInInfoEx2() method allows me to define the button style whereas SetAddInInfoEx() requires the use of the AddCommandBarButton() method to create the button and define the style.


I don't know what examples you're looking at to develop your addin but at glance they appear woefully outdated. For example, your code is using SetAddInInfo(). SetAddInInfoEx() has been available since V20 and SetAddInInfoEx2() has been available since ST7.


My suggestion to people that don't want to use my templates and NuGet packages is to download the SolidEdge.Community.AddIn repository, open SolidEdge.Community.AddIn.sln, execute Registration.bat as an administrator and start debugging the TestAddIn. This allows you to debug my SolidEdge.Community.AddIn.dll and learn how to do these things yourself if you choose to do so.


Developing COM addins in .NET is not easy. Actually can be quite difficult at times hence why I open sourced my code. There is 16 years of my Solid Edge addin knowledge in that code. For example, my SolidEdgeAddIn.cs base class is designed to load the addin into a new and completely separate AppDomain. Long story on why it's important (COM Interop related). People also have fun trying to provide a DLL with native resources for your button images. .NET assemblies don't have these types of native resources by default and Solid Edge requires them for images. That is why I created the EmbedNativeResources project. If you use my templates and NuGet packages, EmbedNativeResources.exe gets executed as a post-build event and does the embedding for you.


Let me know if you have more questions. I'm happy to help in any way that I can.

Jason Newell
Applications Architect