DockableWindow re-open after closing

DockableWindow re-open after closing

mallorn
Advocate Advocate
567 Views
1 Reply
Message 1 of 2

DockableWindow re-open after closing

mallorn
Advocate
Advocate

I have an issue with an Inventor 2017 AddIn,when user closes the UserControll on Dockable Window.
I don't know how to make it open again "properly".

I should probably implement the Remove() or Dispose() UserControll event on Dockable Window closing...

Please advice me how to do it right.

 

StandardAddInServer.cs:

 

 

invApp = addInSiteObject.Application;
public int DWnum = 0;
void landing_buttonDef_OnExecute(NameValueMap Context)
{
	UserControl DW;
	DW = new DockableWindow.landings(invApp, DWnum++);
}

 

 

 

 


landings.cs:

 

public partial class landings : UserControl
    {
        const string kInternalNameFmt = "TestWindow";
        const string kTitleFmt = "Test Window";
        int kWindowNumber;

        public landings(Inventor.Application invApp, int DWnum)
        {
            InitializeComponent();
            kWindowNumber = DWnum;
            ShowDockableWindow(invApp);
		}
		
	void ShowDockableWindow(Inventor.Application invApp, )
	{
		string windowInternalName = String.Format(kInternalNameFmt);
		string windowTitle = String.Format(kTitleFmt);
		UserInterfaceManager uiMgr = invApp.UserInterfaceManager;
		try
		{
				myDockableWindow = uiMgr.DockableWindows.Add(StandardAddInServer.ClientIdString, windowInternalName+kWindowNumber.ToString(), windowTitle);
				myDockableWindow.AddChild(this.Handle);
				this.Visible = true;
				myDockableWindow.Visible = true;
		} catch (Exception e){}
	}
}

 

 

 

 

 

2 variants to myDockableWindow = uiMgr.DockableWindows.Add(...) above, which I would like to "repair":

  • windowInternalName+kWindowNumber.ToString() :
    makes the UserControll button to work, but each next session will "remember" previously used string and will start only the new one (so user will have to click button more and more times each time he starts new Inventor session)
  • windowInternalName:
    If user closes UserControll dockable window, it will be not possible to start it again, giving error:
    Message = "The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))"
    StackTrace = " at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)\r\n at Inventor.DockableWindows.Add(String ClientId, String InternalName, String Title)\r\n ...
    TargetSite = {System.Object ForwardCallToInvokeMember(System.String, System.Reflection.BindingFlags, System.Object, Int32[], System.Runtime.Remoting.Proxies.MessageData ByRef)

.

-------------------------
Tomasz Malinowski
0 Likes
Accepted solutions (1)
568 Views
1 Reply
Reply (1)
Message 2 of 2

yan.gauthier
Advocate
Advocate
Accepted solution

Hi,

 

I fixed that issue by deleting the dockableWindow in the constructor before creating it another time

 

 

UserInterfaceManager userInterfaceManager = inventorApplication.UserInterfaceManager;
foreach (DockableWindow dockableWindow in userInterfaceManager.DockableWindows)
{
    if (dockableWindow.InternalName == "TestWindow")
    {
        dockableWindow.Visible = false;
        userInterfaceManager.DockableWindows["TestWindow"].Delete();
    }
}

 

0 Likes