I have a script that opens a popup form when a custom button is clicked in the ribbon. In the code, this was implemented using the code snippet:
override protected void ButtonDefinition_OnExecute(NameValueMap context)
{
if (InventorApplication.ActiveEditObject is Inventor.PartDocument)
{
MyWin win = new MyWin();
win.Show();
}
else
{
MessageBox.Show("A part document must be active for this command");
}
}
Also note that this window must not be modal i.e., I cannot use win.ShowMessage(); because there is a button on this window that invokes e.g., the line of code
pickedFace = StandardAddInServer.m_inventorApplication.CommandManager.Pick(Inventor.SelectionFilterEnum.kPartFaceFilter,"Pick Face") as Face;
which will not work properly if the window is modal.
I wish to keep focus on MyWin. You would think that one way to do this is to put the handle of the parent window inside the parentheses of win.Show(); However, the parent window appears to be the Inventor main window itself. Does anybody know what is the handle of the parent window, so I can keep focus on the popup window MyWin?
Thank you.
Here's the code to get Inventor's window handle to do what you need.
void btnDoSomething_OnExecute(NameValueMap Context) { MyWinForm myWin = null; if (appInventor.ActiveDocument.DocumentType == DocumentTypeEnum.kPartDocumentObject) { myWin = new MyWinForm(); NativeWindow hWnd = new NativeWindow(); hWnd.AssignHandle((IntPtr)m_inventorApplication.MainFrameHWND); myWin.Show(hWnd);
}
else
{
MessageBox.Show("A part document must be active for this command");
} }