Code for opening a form when a button created by addin is clicked

Code for opening a form when a button created by addin is clicked

2019mmp003
Contributor Contributor
500 Views
1 Reply
Message 1 of 2

Code for opening a form when a button created by addin is clicked

2019mmp003
Contributor
Contributor

Hi all, I hope you are doing good.

 

I have developed an add-in in which I was able to create a button and add a image to the button. I tried searching for the code to implement opening of a form when the button is clicked in c#. There are references for the same using visual Basic but as I am beginner into inventor programming I was not able to convert into c#. So please can you write a code for only opening the form when the button is clicked.


I would Like to share my coded part until now.

m_inventorApplication = addInSiteObject.Application;

ControlDefinitions conDefs = m_inventorApplication.CommandManager.ControlDefinitions;

m_UserInterfaceEvents = m_inventorApplication.UserInterfaceManager.UserInterfaceEvents;

Ribbon ribbon = m_inventorApplication.UserInterfaceManager.Ribbons["Part"];

RibbonTab ribbonTab;

try
{
ribbonTab = ribbon.RibbonTabs["id_TabModel"];
}

catch (Exception)
{
ribbonTab = ribbon.RibbonTabs.Add("3D Model", "id_TabModel", Guid.NewGuid().ToString());
}

RibbonPanel ribbonPanel;

ribbonPanel = ribbonTab.RibbonPanels.Add("3D Objects", "id_PanelP_ModelObjects", Guid.NewGuid().ToString());

 


//string projectPath = System.IO.Directory.GetCurrentDirectory();

//string smallPicFileName = System.IO.Path.Combine(projectPath, "small.png");
//string bigPicFileName = System.IO.Path.Combine(projectPath, "big.png");

stdole.IPictureDisp smallPic = null;

stdole.IPictureDisp bigPic = null;

//System.Drawing.Bitmap small = new Bitmap(smallPicFileName);
//System.Drawing.Bitmap big = new Bitmap(bigPicFileName);

smallPic = PictureConverter.ImageToPictureDisp(Properties.Resources.small);

bigPic = PictureConverter.ImageToPictureDisp(Properties.Resources.big);

definition = conDefs.AddButtonDefinition("CageModeller", "id_CageModeller", Inventor.CommandTypesEnum.kShapeEditCmdType,
Guid.NewGuid().ToString(), "Feature to easily model the anticavitation Cage"
, "Cage Modeller" + "\n\n Feature to easily model the anticavitation Cage", smallPic, bigPic);


ribbonPanel.CommandControls.AddButton(definition);




0 Likes
Accepted solutions (1)
501 Views
1 Reply
Reply (1)
Message 2 of 2

JelteDeJong
Mentor
Mentor
Accepted solution

Your ButtonDefinition that you created.

definition = conDefs.AddButtonDefinition("CageModeller", "id_CageModeller", Inventor.CommandTypesEnum.kShapeEditCmdType,
Guid.NewGuid().ToString(), "Feature to easily model the anticavitation Cage"
, "Cage Modeller" + "\n\n Feature to easily model the anticavitation Cage", smallPic, bigPic);

has an event that you can use to start the form. something like this.

definition.OnExecute += SettingsButton_OnExecute;

Then the function "SettingsButton_OnExecute" will look something like this:

private void SettingsButton_OnExecute(NameValueMap Context)
{
    YourForm form = new YourForm();
    form.ShowDialog();
}

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes