Hello there,
I'm currently reviewing the tools I have created over the years, and I would like to do an improvement.
So I did a some testing and find that my tools work, but they are still a little bit complecated to use. So this improvement I like to make would refer to the user interface of the tools.
To improve my tools I would like to work with a dockable window. But.. I can't find a good sample of how to make one. Could one of you share sample code? Or a vb project that contains it? that would be great.
I found this code sample but it's not realy clear to me.
Sub DockableWindow() Dim oUserInterfaceMgr As UserInterfaceManager Set oUserInterfaceMgr = ThisApplication.UserInterfaceManager ' Create a new dockable window Dim oWindow As DockableWindow Set oWindow = oUserInterfaceMgr.DockableWindows.Add("SampleClientId", "TestWindowInternalName", "Test Window") ' Get the hwnd of the dialog to be added as a child ' CHANGE THIS VALUE! Dim hwnd As Long hwnd = 4851096 ' Add the dialog as a child to the dockable window Call oWindow.AddChild(hwnd) ' Don't allow docking to top and bottom oWindow.DisabledDockingStates = kDockTop + kDockBottom ' Make the window visible oWindow.Visible = True End Sub
Solved! Go to Solution.
Solved by NachitoMax. Go to Solution.
I managed to get a visible dockable window and my windows form in it.
Private Sub CreateDockableWindow() ' Set reference to the user interface manager Dim oUserInterfaceMgr As UserInterfaceManager oUserInterfaceMgr = m_inventorApplication.UserInterfaceManager ' Create a new dockable window Dim oWindow As DockableWindow oWindow = oUserInterfaceMgr.DockableWindows.Add("SampleClientId", "TestWindowInternalName", "Test Window") Dim oForm As New FileInfo oWindow.AddChild(oForm.Handle) ' Dock the window to the right oWindow.DockingState = DockingStateEnum.kDockRight oWindow.Visible = True End Sub
How can you the form to be displayed withour the border ( close form button )?
Okay, stupid question found it!
@Anonymous
So I added a dockable window that loads when Inventor is activated. I made in my visual studio solution a windowsform and added a textbox and button on it. But when I can't see any of it on my dockable window?
Private Sub CreateDockableWindow() ' Set reference to the user interface manager Dim oUserInterfaceMgr As UserInterfaceManager oUserInterfaceMgr = m_inventorApplication.UserInterfaceManager ' Create a new dockable window Dim oWindow As DockableWindow oWindow = oUserInterfaceMgr.DockableWindows.Add("SampleClientId", "TestWindowInternalName", "Test Window") Dim oForm As New FileInfo oWindow.AddChild(oForm.Handle) ' Dock the window to the right oWindow.DockingState = DockingStateEnum.kDockRight oWindow.Width = 50 oWindow.Visible = True End Sub
How can I make my controls visible?
Here are 2 screenshots to show whats going on.
This is what I see in Inventor
This is what i see in Visual Studio
Hi
In visual studio, why dont you create a usercontrol instead (as it has no borders), add all of your controls into that and add it into the dockable window?
This is how i have done it:
Imports System.Runtime.InteropServices Imports System Imports System.Type Imports System.Activator Imports Microsoft.VisualBasic Imports Inventor Imports System.IO Imports System.Drawing Imports System.Collections Imports System.ComponentModel Imports System.Windows.Forms Imports System.Data Module DockWindow Public oWindow As Inventor.DockableWindow Public IsBrowserVisible As Boolean = True Public DockHeight As Long = 500 Public dockWidth As Long = 350 Public DockShown As Boolean = False Private InitialDockHeight As Long = 0 Private InitialDockWidth As Long = 0 Public InAction As Boolean = False Private addInCLSIDString As String Private dc As Test01 Public Sub SetDockableWindow(addInCLS As String) Dim oUserInterfaceMgr As Inventor.UserInterfaceManager = AddinGlobal.InventorApp.UserInterfaceManager Try oWindow = oUserInterfaceMgr.DockableWindows.Add(addInCLS, "AutoSheetDockWindow", "Auto Sheets") oWindow.AddChild(CreateChildDialog()) oWindow.DisabledDockingStates = DockingStateEnum.kDockTop + DockingStateEnum.kDockBottom oWindow.Visible = False 'Dont show the window on loading. Set to True to show on startup Catch ex As Exception End Try End Sub Public Function CreateChildDialog() As Long If Not dc Is Nothing Then dc.Dispose() dc = Nothing End If dc = New Test01() dc.Show(New WindowWrapper(AddinGlobal.InventorApp.MainFrameHWND)) Return dc.Handle.ToInt64() End Function Public Sub DockVis(visible As Boolean) Dim oUserInterfaceMgr As Inventor.UserInterfaceManager = AddinGlobal.InventorApp.UserInterfaceManager Select Case visible Case True oUserInterfaceMgr.ShowBrowser = False oWindow.Visible = visible Select Case DockShown Case False oWindow.DockingState = DockingStateEnum.kDockLeft oWindow.SetMinimumSize(DockHeight, dockWidth) DockShown = True End Select Case False oWindow.Visible = visible oUserInterfaceMgr.ShowBrowser = IsBrowserVisible End Select End Sub End Module
Note:
you can add a form in the exact same way, just declare dc as the form instead. Set your form to have no borders and turn off the buttons in the forms properties
This code shows the dock bar when a button is clicked and closes it when its i click a close button. Here is the button code in the ButtonActions Class
'Namespace autosheet Public Class ButtonActions Public Shared Sub Button1_Execute() 'TODO: add code below for the button click callback. Dim oUserInterfaceMgr As Inventor.UserInterfaceManager = AddinGlobal.InventorApp.UserInterfaceManager Select Case InAction Case True Exit Sub Case False DockWindow.IsBrowserVisible = oUserInterfaceMgr.ShowBrowser DockWindow.DockVis(True) oUserInterfaceMgr = Nothing DockWindow.InAction = True End Select End Sub End Class
in my close button, i use this:
DockWindow.InAction = False DockWindow.DockVis(False)
I turn off the main browser to only have mine there during usage. it is turned off here:
It also docks the window to the left. this can be changed in this line of code:
It is controlled by the 'Visible As Boolean' in the above sub
hope that helps
Nacho
Nacho
Automation & Design Engineer
Inventor Programmer (C#, VB.Net / iLogic)
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.
Hi Nacho,
Just a few years late... 🙂
In your example do you use a button to controls if is visible or not.
But how to make the dock.window visible together the Browser Panel or when do you open a type file.. ?
Thanks in advance,
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.
Cristiano Oliveira
ConsultCAD.com
when i load my app, i make the doc window visible and when i close the app, i make it false again. there is a section in the code posted that shows how i turn off the browser window to just have mine. you can comment it out and it wont turn the browser window off
hth
Nacho
Automation & Design Engineer
Inventor Programmer (C#, VB.Net / iLogic)
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.
Hello,
I've been testing with snippets above, but I can't figure out how to make my controls show within my User Control form.
If I however try to add a different Form as the docked form it works.
Imports Inventor
Public Class DockWindow
' Private dc As DockWindow 'This doesn't work
Private dc As New_part 'This works
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
CreateDockableWindow()
End Sub
Public Sub CreateDockableWindow()
' Set reference to the user interface manager
Dim oUserInterfaceMgr As UserInterfaceManager = g_inventorApplication.UserInterfaceManager
' Create a new dockable window
Dim oWindow As Inventor.DockableWindow = oUserInterfaceMgr.DockableWindows.Add(g_inventorApplication.UserName, "TestWindowInternalName", "Kassist")
Try
oWindow.AddChild(CreateChildDialog())
Catch ex As Exception
MsgBox(ex.Message) 'Throws expection if I use dc = DockWindow
End Try
End Sub
Public Function CreateChildDialog() As Long
If Not dc Is Nothing Then
dc.Dispose()
dc = Nothing
End If
'dc = New DockWindow()'This doesn't work
dc = New New_part 'This works
dc.Show()
Return dc.Handle.ToInt64()
End Function
End Class
I call this in StandardAddInServer.vb
Private Sub invEvents_OnActivateDocument(DocumentObject As _Document, BeforeOrAfter As EventTimingEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum) Handles invEvents.OnActivateDocument
If BeforeOrAfter = EventTimingEnum.kAfter Then
Dim DockedWindow As New DockWindow
End If
End Sub
Exception message if dc = DockWindow:
Anyone know how I can solve this?
Do I need 1 class + 1 user control?
Bonus question: Using the code that @NachitoMax provided, I can't seem to figure out how he creates the children without it being inside DockVis. From his screenshot it looks like he referenced it 2 times, which I assume is for show & hide. How did he reference it, and how does that trigger the CreateChild Function?
I wrote a tutorial about creating an Inventor addin. You might want to check out the part "Creating a dockable window ". It's possible to create dockable windows from wpf forms.
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.
Blog: hjalte.nl - github.com
Thanks, I'll definitely take a look.
I did manage to solve my issue with the help from This post. Important to note for future readers is to add a StatusStrip to the control (either by code or from the visual studio toolbox) otherwise the form will hide itself for some reason.
Public Sub New(addInCLSIDString As String)
' This call is required by the designer.
InitializeComponent()
' Get the UserInterfaceManager from the global Inventor Application object
Dim oUserInterFaceManager As UserInterfaceManager = g_inventorApplication.UserInterfaceManager
' Get the DockableWindows collection from the UserInterfaceManager
Dim _DockableWindows As DockableWindows = oUserInterFaceManager.DockableWindows
' Check if the window instance with title "Kassist" already exists
Dim InstanceFound As Boolean = False
For Each oWindows As Inventor.DockableWindow In _DockableWindows
If oWindows.Title = "Kassist" Then
' If the window instance is found, add the current instance as a child of the window
oWindows.AddChild(Me.Handle)
oWindows.Visible = True
InstanceFound = True
End If
Next
' If the window instance does not exist, create a new window and add the current instance as a child
Dim oWindow As Inventor.DockableWindow
If InstanceFound = False Then
oWindow = oUserInterFaceManager.DockableWindows.Add(addInCLSIDString, g_inventorApplication.ActiveDocument.DisplayName, "Kassist")
oWindow.AddChild(Me.Handle)
oWindow.Visible = True
End If
End Sub
This code above is a lot shorter than the codes given by other users in this thread, and could possibly to shortened even further.
I trigger this from StadardAddInServer.vb, which works but probably could be written more nicely.
Public Sub Activate(ByVal addInSiteObject As Inventor.ApplicationAddInSite, ByVal firstTime As Boolean) Implements Inventor.ApplicationAddInServer.Activate
Dim addInCLS As GuidAttribute = CType(System.Attribute.GetCustomAttribute(GetType(StandardAddInServer), GetType(GuidAttribute)), GuidAttribute)
addInCLSIDString = "{" & addInCLS.Value & "}"
End Sub
' add events
Private Sub invEvents_OnActivateDocument(DocumentObject As _Document, BeforeOrAfter As EventTimingEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum) Handles invEvents.OnActivateDocument
If BeforeOrAfter = EventTimingEnum.kAfter Then
Dim DockedWindow As New DockWindow(addInCLSIDString)
End If
End Sub
Private Sub invEvents_OnCloseDocument(DocumentObject As _Document, FullDocumentName As String, BeforeOrAfter As EventTimingEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum) Handles invEvents.OnCloseDocument
If BeforeOrAfter = EventTimingEnum.kBefore Then
'If Documents.Count = 1 before closing the document, it will hide the form.
If g_inventorApplication.Documents.Count = 1 Then
'' Set reference to the user interface manager
Dim oUserInterFaceManager As UserInterfaceManager = g_inventorApplication.UserInterfaceManager
Dim _DockableWindows As DockableWindows = oUserInterFaceManager.DockableWindows
For Each WindowInstance As Inventor.DockableWindow In _DockableWindows
If WindowInstance.Title = "Kassist" Then
WindowInstance.Visible = False
End If
Next
End If
End If
Can't find what you're looking for? Ask the community or share your knowledge.