Message 1 of 3
Addin doesnt open window or messagebox
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Like in the title. My inventor addin doesnt open a window or messagebox and i cant figure out why.
My code is as follows:
public void Activate(ApplicationAddInSite addInSiteObject, bool firstTime)
{
inventorApplication = addInSiteObject.Application;
// Create a new RibbonTab
RibbonTab ribbonTab = inventorApplication.UserInterfaceManager.Ribbons["Part"].RibbonTabs.Add("HorizonTab", "Horizon Tab", "a86e9d80-d720-4020-97b2-244323f99115");
// Create a new RibbonPanel
RibbonPanel ribbonPanel = ribbonTab.RibbonPanels.Add("HorizonPanel", "Horizon Panel", "a86e9d80-d720-4020-97b2-244323f99115");
// Create a ButtonDefinition for opening a window
ButtonDefinition openWindowButton = inventorApplication.CommandManager.ControlDefinitions.AddButtonDefinition(
"OpenWindowButton",
"Open Window",
CommandTypesEnum.kEditMaskCmdType,
"{yourClientId}",
"Sample text for opening a window",
"icon_open_window.ico"
);
// Create a ButtonDefinition for displaying a message box
ButtonDefinition messageBoxButton = inventorApplication.CommandManager.ControlDefinitions.AddButtonDefinition(
"MessageBoxButton",
"Show Message",
CommandTypesEnum.kEditMaskCmdType,
"{yourClientId}",
"Sample text for displaying a message box",
"icon_message_box.ico"
);
// Register event handlers for button clicks
openWindowButton.OnExecute += OpenWindowHandler;
messageBoxButton.OnExecute += MessageBoxHandler;
// Add the buttons to the ribbon panel
ribbonPanel.CommandControls.AddButton(openWindowButton, false);
ribbonPanel.CommandControls.AddButton(messageBoxButton, false);
}
private void OpenWindowHandler(NameValueMap context)
{
// Debugging check
System.Diagnostics.Debug.WriteLine("OpenWindowHandler called");
// Implement the code to open a window here (using Windows Forms)
Form window = new Form();
window.Text = "Sample Window";
window.Size = new System.Drawing.Size(400, 200);
window.Controls.Add(new Label() { Text = "This is a sample window." });
// Start a message loop for the window
System.Windows.Forms.Application.Run(window);
// window.ShowDialog();
}
private void MessageBoxHandler(NameValueMap context)
{
// Debugging check
System.Diagnostics.Debug.WriteLine("MessageBoxHandler called");
// Display a message box with the sample text
MessageBox.Show("Sample text for displaying a message box", "Message Box");
}
Can someone help me with this. Note, it is my first programming in C#.