[VB.net] Ensure dockable window is loaded after Model, Vault and iLogic windows have been loaded/shown

[VB.net] Ensure dockable window is loaded after Model, Vault and iLogic windows have been loaded/shown

Steffen_Hoerup
Participant Participant
702 Views
5 Replies
Message 1 of 6

[VB.net] Ensure dockable window is loaded after Model, Vault and iLogic windows have been loaded/shown

Steffen_Hoerup
Participant
Participant

I am trying to create a dockable window. I have tried most of the solutions I have founf on this forum, but I never get it to work - All windows are collapsing to the left side:

Steffen_Hoerup_0-1690036118195.png

 

I have adapted the code from  Dockable window going empty, so it conforms to NiftyAddinTemplate:

			Dim oUserInterFaceManager As UserInterfaceManager
			Dim _DockableWindows As DockableWindows
			Dim oDockableWindowsEvents As DockableWindowsEvents
			Dim oWindow As DockableWindow
			Dim StatusStrip As System.Windows.Forms.StatusStrip
			Dim InstanceFound As Boolean

			oUserInterFaceManager = g_inventorApplication.UserInterfaceManager
			_DockableWindows = oUserInterFaceManager.DockableWindows

			For Each WindowInstance As DockableWindow In _DockableWindows
				If WindowInstance.Title = "DockableWindow" Then
					WindowInstance.AddChild(StatusStrip.Handle.ToInt64())
					InstanceFound = True
				End If
			Next
			If InstanceFound = False Then
				oWindow = oUserInterFaceManager.DockableWindows.Add("SomeOtherSortOfCliendId", "DockableWindowInternalName", "DockableWindow")
				oWindow.AddChild(StatusStrip.Handle.ToInt64())
			End If

 

If I run the above code from a button, after the document and its model, vault and iLogic-panes, it adds the dockable window as it should.

If the code is triggered before that, I get the result shown in the image above.

I belive it is because my dockable windows is created before the panes are loaded.

 

the question:

What event-trigger or handlers do I need to use to run the above code, so the other panes are loaded before I add the dockable code?

I can't figure it out from the examples on this forum.

I can't figure this out. The

0 Likes
Accepted solutions (2)
703 Views
5 Replies
Replies (5)
Message 2 of 6

jjstr8
Collaborator
Collaborator

It worked more consistently for me if I created the dockable window in the UserInterfaceEvents.OnEnvironmentChange event rather than the addin Activate method.  If it's not environment dependent, create it when the event fires with EnvirnomentState equal to  EnvironmentStateEnum.kActivateEnvironmentState and your dockable window field is null.  I didn't find that kBefore or kAfter made a difference. 

0 Likes
Message 3 of 6

Michael.Navara
Advisor
Advisor
Accepted solution

In my opinion your code sample is incomplete.

If you want to create dockable window with some custom content, you need to implement at least two classes. First for UserControl definition and second for ApplicationAddInServer implementation.

Variables for DockableWindow and UserControl must be defined at class level (not method level)

 

Minimalistic code sample without error handling etc.

 

Public Class MyAddinServer
    Implements ApplicationAddInServer

    Private clientId As String = "{00000000-0000-0000-0000-000000000000}"
    Private inventor As Inventor.Application
    Private dockablWindow As DockableWindow
    Private myControl As MyControl

    Public Sub Activate(addInSiteObject As ApplicationAddInSite, firstTime As Boolean) Implements ApplicationAddInServer.Activate
        inventor = addInSiteObject.Application

        myControl = New MyControl()
        dockablWindow = inventor.UserInterfaceManager.DockableWindows.Add(clientId, "DockableWindowInternalName", "Title")
        dockablWindow.AddChild(myControl.Handle)
    End Sub

    Public Sub Deactivate() Implements ApplicationAddInServer.Deactivate

        dockablWindow.Clear()
        dockablWindow.Delete()

        'Release objects.
        inventor = Nothing

        GC.Collect()
        GC.WaitForPendingFinalizers()

    End Sub

    Public Sub ExecuteCommand(commandId As Integer) Implements ApplicationAddInServer.ExecuteCommand
        'Throw New NotImplementedException
    End Sub

    Public Property Automation As Object Implements ApplicationAddInServer.Automation
End Class

 

This class is almost automatically generated by WinForms editor. You don't need to modify the code directly.

Imports System.Windows.Forms

Public Class MyControl
    Inherits UserControl

    Friend WithEvents StatusStrip1 As StatusStrip

    Public Sub New()
        InitializeComponent()
    End Sub

    Private Sub InitializeComponent()
        Me.StatusStrip1 = New System.Windows.Forms.StatusStrip()
        Me.SuspendLayout()
        '
        'StatusStrip1
        '
        Me.StatusStrip1.Dock = System.Windows.Forms.DockStyle.Top
        Me.StatusStrip1.Location = New System.Drawing.Point(0, 0)
        Me.StatusStrip1.Name = "StatusStrip1"
        Me.StatusStrip1.Size = New System.Drawing.Size(150, 22)
        Me.StatusStrip1.TabIndex = 0
        Me.StatusStrip1.Text = "StatusStrip1"
        '
        'MyControl
        '
        Me.Controls.Add(Me.StatusStrip1)
        Me.Name = "MyControl"
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
End Class

 

 

Complete C# sample from real application is HERE

 

Message 4 of 6

Steffen_Hoerup
Participant
Participant

Thanks for both of your replies.

 

I know the code was incoplete, as i had not assigned a user Control to the window. I was trying to create a project from scratch, so I did not have to worry about other factors than getting the dockable window to work.

 

I have now implemented you code @Michael.Navara. The dockable window works, but I still have an issue, that it collapses all the panes when I open Inventor from scratch. I want to be able to control the position, before I add content 🙂

 

In the video below, you can see how it troubles me. If I dock the dockable window below the browser pane, it will collapse panes when I open inventor from scratch. If I have it floating it works. So I imagine, it is because the dockable window is created when Inventor opens, and here there is no browser panel it can dock below - ie it finds a new position, and that causes the panes to collapse when I open up the part environment.

 

 

So right now, I am looking for a solution to be able to dock below/above other windows. Is it possible to limit the loading, so it does not happen at inventor startup?

0 Likes
Message 5 of 6

Michael.Navara
Advisor
Advisor
Accepted solution
  • You can modify "LoadBehavior" value in .addin file. See here for more info.
  • You can wait for OnReady event and set the position.
  • You can create DockableWindow hidden and show them when needed
  • or something else... 😉
Message 6 of 6

Steffen_Hoerup
Participant
Participant

It was something like the OnReady i was looking for, but didn't manage to find.

However, I think the LoadBehavior-method does the job, so I'll go with that.

 

It seems so easy when you know the answer 🙂

 

Thanks for the help!.

 

0 Likes