Add-in + Dockable Window

Add-in + Dockable Window

MechMachineMan
Advisor Advisor
5,413 Views
8 Replies
Message 1 of 9

Add-in + Dockable Window

MechMachineMan
Advisor
Advisor

What am I missing here? It's creating the docked window, but not creating it's children.

 

So far all I have done is add a user control with some common controls on it and put this code in there:

 

Public Class UserControl1

    Dim dc As UserControl1

    Public Sub New(ByVal Application As Inventor.Application)

        InitializeComponent()

        Dim _InvApp As Inventor.Application
        _InvApp = Application

        Dim _ApplicationEvents As Inventor.ApplicationEvents
        _ApplicationEvents = _InvApp.ApplicationEvents

        Dim _UserInputEvents As Inventor.UserInputEvents
        _UserInputEvents = _InvApp.CommandManager.UserInputEvents

        ' Add a event handlers to catch the user selection changes
        AddHandler _ApplicationEvents.OnActivateDocument, AddressOf Document_Activated
        AddHandler _UserInputEvents.OnSelect, AddressOf UserSelect
        AddHandler _UserInputEvents.OnUnSelect, AddressOf UserUnSelect

        Dim oUserInterfaceMgr As Inventor.UserInterfaceManager
        oUserInterfaceMgr = _InvApp.UserInterfaceManager

        Dim _Browser As Inventor.DockableWindow
        _Browser = oUserInterfaceMgr.DockableWindows.Add("SampleClientId", "DDCIntName", "Ellimetal DDC")

        _Browser.AddChild(CreateChildDialog())
        _Browser.DockingState = Inventor.DockingStateEnum.kDockRight
        _Browser.ShowTitleBar = True
        _Browser.Visible = True
        _Browser.Width = 220
    End Sub

    Public Function CreateChildDialog() As Long

        If Not dc Is Nothing Then
            dc.Dispose()
            dc = Nothing
        End If

        dc = New UserControl1(g_inventorApplication)
        dc.Show()
        Return dc.Handle.ToInt64()
    End Function

    Private Sub Document_Activated()
        Throw New NotImplementedException
    End Sub

    Private Sub UserSelect()
        Throw New NotImplementedException
    End Sub

    Private Sub UserUnSelect()
        Throw New NotImplementedException
    End Sub

End Class

As well as adding this line into the StandardAddInServer.Vb under the Activate Method:

 

        Public Sub Activate(ByVal addInSiteObject As Inventor.ApplicationAddInSite, ByVal firstTime As Boolean) Implements Inventor.ApplicationAddInServer.Activate
            ' Initialize AddIn members.
            g_inventorApplication = addInSiteObject.Application

            ' Connect to the user-interface events to handle a ribbon reset.
            m_uiEvents = g_inventorApplication.UserInterfaceManager.UserInterfaceEvents

            Dim oBrowser As New UserControl1(g_inventorApplication)

I'm trying to take it one step at a time to get an idea of what I'm actually doing seeing as I have not made an add-in before.

Seems kind of overwhelming to start with all of extra lines of code in the project that I dont even need to look at, and not really having a clear idea of how it all works together...

 

Thanks in advance!


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
5,414 Views
8 Replies
Replies (8)
Message 2 of 9

MechMachineMan
Advisor
Advisor

@Jef_E do you have any insight you would be willing to share on this?


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 9

MechMachineMan
Advisor
Advisor

@adam.nagy@ekinsb

 

Could someone at least point me in the right direction for getting something like this working?

 

After reading this blog post, I'm sure I could hard code something in that would work, but doesn't it make more sense to design it as a user control for implementation?

 

Is the fact that I'm trying to do it as a UserControl and not a UserControl with WPF what is causing me issues?

This blog post leads me to think that could be a potential issue.

 

Below is the code that I currently have, from the Autodesk Inventor Addin Template used in Visual Studio (2013?) with the built-in template components that I deduced were irrelevant skimmed out of it and my additional peices added in.

 

-- StandardAddinServer.vb--

 

Imports Inventor
Imports System.Runtime.InteropServices
Imports Microsoft.Win32

Namespace MmmiPropWindow
    <ProgIdAttribute("MmmiPropWindow.StandardAddInServer"), _
    GuidAttribute("08d32409-f652-4368-b280-479da00bb063")> _
    Public Class StandardAddInServer
        Implements Inventor.ApplicationAddInServer

        Private WithEvents m_uiEvents As UserInterfaceEvents

#Region "ApplicationAddInServer Members"

        Public Sub Activate(ByVal addInSiteObject As Inventor.ApplicationAddInSite, ByVal firstTime As Boolean) Implements Inventor.ApplicationAddInServer.Activate
            ' Initialize AddIn members.
            g_inventorApplication = addInSiteObject.Application

            ' Connect to the user-interface events to handle a ribbon reset.
            m_uiEvents = g_inventorApplication.UserInterfaceManager.UserInterfaceEvents

            Dim oBrowser As New UserControl1(g_inventorApplication)
            oBrowser.Show()

            If firstTime Then
                AddToUserInterface()
            End If
        End Sub


        Public Sub Deactivate() Implements Inventor.ApplicationAddInServer.Deactivate
            ' Release objects.
            m_uiEvents = Nothing
            g_inventorApplication = Nothing

            System.GC.Collect()
            System.GC.WaitForPendingFinalizers()
        End Sub

#End Region

    End Class
End Namespace


Public Module Globals
    ' Inventor application object.
    Public g_inventorApplication As Inventor.Application

End Module

 --UserControl1.vb--

 

Public Class UserControl1

    Private dc As UserControl1
    Private _InvApp As Inventor.Application

    Public Sub New(ByVal Application As Inventor.Application)

        Call InitializeComponent()

        'Dim _InvApp As Inventor.Application
        _InvApp = Application

        Dim _ApplicationEvents As Inventor.ApplicationEvents
        _ApplicationEvents = _InvApp.ApplicationEvents

        Dim _UserInputEvents As Inventor.UserInputEvents
        _UserInputEvents = _InvApp.CommandManager.UserInputEvents

        ' Add a event handlers to catch the user selection changes
        'AddHandler _ApplicationEvents.OnActivateDocument, AddressOf Document_Activated
        'AddHandler _UserInputEvents.OnSelect, AddressOf UserSelect
        'AddHandler _UserInputEvents.OnUnSelect, AddressOf UserUnSelect

        Dim oUserInterfaceMgr As Inventor.UserInterfaceManager
        oUserInterfaceMgr = _InvApp.UserInterfaceManager

        Dim _Browser As Inventor.DockableWindow
        _Browser = oUserInterfaceMgr.DockableWindows.Add(Guid.NewGuid().ToString(), "MmmiPropWindowDockable", "MmmiPropWindow")
        Me.Controls.Add(ComboBox1)
        _Browser.AddChild(Me)
        _Browser.AddChild(CreateChildDialog())

        Me.Controls.Add(ListView1)
        _Browser.DockingState = Inventor.DockingStateEnum.kDockRight
        _Browser.ShowTitleBar = True
        _Browser.ShowVisibilityCheckBox = True
        _Browser.Title = "MMMiPropWindow"
        _Browser.Caption = "Huh"
        _Browser.Width = 220
        _Browser.Height = 1200
        _Browser.Visible = True
    End Sub

    Public Function CreateChildDialog() As Long

        If Not dc Is Nothing Then
            dc.Dispose()
            dc = Nothing
        End If

        dc = New UserControl1(_InvApp)
        dc.Height = 100
        dc.Width = 100
        dc.MinimumSize = New Drawing.Size(dc.Height, dc.Width)

        dc.Controls.Add(ListView1)
        dc.Show()

        Return dc.Handle.ToInt64()
    End Function

End Class

 

-- UserControl1.Designer.vb--

 

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class UserControl1
    Inherits System.Windows.Forms.UserControl

    'UserControl overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Public Sub InitializeComponent()
        Dim ColumnHeader1 As System.Windows.Forms.ColumnHeader
        Me.ComboBox1 = New System.Windows.Forms.ComboBox()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.TextBox1 = New System.Windows.Forms.TextBox()
        Me.ComboBox2 = New System.Windows.Forms.ComboBox()
        Me.TextBox2 = New System.Windows.Forms.TextBox()
        Me.GroupBox1 = New System.Windows.Forms.GroupBox()
        Me.ListView1 = New System.Windows.Forms.ListView()
        Me.ColumnHeader2 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)
        ColumnHeader1 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)
        Me.GroupBox1.SuspendLayout()
        Me.SuspendLayout()
        '
        'ComboBox1
        '
        Me.ComboBox1.FormattingEnabled = True
        Me.ComboBox1.Location = New System.Drawing.Point(3, 3)
        Me.ComboBox1.Name = "ComboBox1"
        Me.ComboBox1.Size = New System.Drawing.Size(121, 21)
        Me.ComboBox1.TabIndex = 0
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(6, 23)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(39, 13)
        Me.Label1.TabIndex = 1
        Me.Label1.Text = "Label1"
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(6, 45)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(39, 13)
        Me.Label2.TabIndex = 2
        Me.Label2.Text = "Label2"
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(91, 16)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(150, 20)
        Me.TextBox1.TabIndex = 3
        '
        'ComboBox2
        '
        Me.ComboBox2.FormattingEnabled = True
        Me.ComboBox2.Location = New System.Drawing.Point(137, 68)
        Me.ComboBox2.Name = "ComboBox2"
        Me.ComboBox2.Size = New System.Drawing.Size(121, 21)
        Me.ComboBox2.TabIndex = 4
        '
        'TextBox2
        '
        Me.TextBox2.Location = New System.Drawing.Point(91, 42)
        Me.TextBox2.Name = "TextBox2"
        Me.TextBox2.Size = New System.Drawing.Size(150, 20)
        Me.TextBox2.TabIndex = 5
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.ListView1)
        Me.GroupBox1.Controls.Add(Me.Label2)
        Me.GroupBox1.Controls.Add(Me.TextBox1)
        Me.GroupBox1.Controls.Add(Me.Label1)
        Me.GroupBox1.Controls.Add(Me.TextBox2)
        Me.GroupBox1.Controls.Add(Me.ComboBox2)
        Me.GroupBox1.Location = New System.Drawing.Point(6, 30)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(264, 382)
        Me.GroupBox1.TabIndex = 6
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "GroupBox1"
        '
        'ListView1
        '
        Me.ListView1.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {ColumnHeader1, Me.ColumnHeader2})
        Me.ListView1.Location = New System.Drawing.Point(6, 95)
        Me.ListView1.Name = "ListView1"
        Me.ListView1.Size = New System.Drawing.Size(252, 281)
        Me.ListView1.TabIndex = 5
        Me.ListView1.UseCompatibleStateImageBehavior = False
        '
        'ColumnHeader1
        '
        ColumnHeader1.Text = "Field"
        '
        'ColumnHeader2
        '
        Me.ColumnHeader2.Text = "Value"
        '
        'UserControl1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.Controls.Add(Me.GroupBox1)
        Me.Controls.Add(Me.ComboBox1)
        Me.Name = "UserControl1"
        Me.Size = New System.Drawing.Size(276, 420)
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox1.PerformLayout()
        Me.ResumeLayout(False)

    End Sub
    Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents ComboBox2 As System.Windows.Forms.ComboBox
    Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents ListView1 As System.Windows.Forms.ListView
    Friend WithEvents ColumnHeader2 As System.Windows.Forms.ColumnHeader

End Class

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 4 of 9

MechMachineMan
Advisor
Advisor

Hi @Jef_E, I saw in your post here that you made the same sort of thing that I'm looking to do, except through a ribbon panel?

 

I was hoping you could spare some insight on what I'm doing wrong here/ any alternative/better means of accomplishing what I'm trying to get at.

 

I started with the idea of writing a new BrowserPane that I would have docked on the right side of the screen that would pull iProperties based off of my select set - something that would function almost identically to the Property Browser in visual studio, except for model files.

 

Thanks in advance,

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 5 of 9

NachoShaw
Advisor
Advisor

Hi

 

Have you looked through the local help files? This is a snippet in VBA

 

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

its all it really needs to make a dockable window. you create you form that has all of your buttons etc and then add it to the dockable window here:

Call oWindow.AddChild(hwnd)

you will need to get the hwnd or Handle of the form at runtime which can be done but is tricky in VBA. The above code can also be sued in Visual Studo but you will to be explicit in the declarations. I made a dockable window application in VB.Net a while ago, i'll see if I can get time to dig it out and provide some coding

 

Nacho

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


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.


Message 6 of 9

MechMachineMan
Advisor
Advisor

Thanks for the reply!

 

I have seen this sample and had used it when I was first coming up with the idea! However, I recall having issues with the HWND and wasn't able to properly get my active x UserControl loaded/working. A sample would definitely be cool to see!


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 7 of 9

NachoShaw
Advisor
Advisor
Hi

Are you doing this on vb.net through visual studio or VBA through the built in IDE?

Depending on the above determines the correct solution


Cheers

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


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.


0 Likes
Message 8 of 9

MechMachineMan
Advisor
Advisor

I was trying to do a "proof of concept" kind of thing with the VBA IDE, but ideally I want to make it as an add-in using Visual Studio in vb.net.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 9 of 9

NachoShaw
Advisor
Advisor

Hi

 

Ok this should work for you in VBA. (I haven't had time to sort out a .Net version but I did post sample code a while ago here. In the link, i created a UserControl instead of a form as it was easier at the time.

 

VBA

Public Declare PtrSafe Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare PtrSafe Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long

Public Declare PtrSafe Function FindWindowA& Lib "user32" (ByVal lpClassName$, ByVal lpWindowName$)
Public Declare PtrSafe Function GetWindowLongA& Lib "user32" (ByVal hWnd&, ByVal nIndex&)
Public Declare PtrSafe Function SetWindowLongA& Lib "user32" (ByVal hWnd&, ByVal nIndex&, ByVal dwNewLong&)
Public Declare PtrSafe Function DrawMenuBar Lib "user32" (ByVal hWnd As Long) As Long

Public Const GWL_STYLE As Long = -16
Public Const WS_MINIMIZEBOX = &H20000
Public Const WS_MAXIMIZEBOX = &H10000
Public Const WS_FULLSIZING = &H70000
Public Const WS_BORDER = &H800000

Public oWindow As DockableWindow


Public Function InitMaxMin(mCaption As String) As Long
Dim hWnd As Long
    hWnd = FindWindowA(vbNullString, mCaption)
    SetWindowLongA hWnd, GWL_STYLE, GetWindowLongA(hWnd, GWL_STYLE) And Not WS_BORDER And Not WS_SIZEBOX And Not WS_DLGFRAME
    DrawMenuBar hWnd
    InitMaxMin = hWnd
End Function

Sub DockableWindow()
    Dim oUserInterfaceMgr As UserInterfaceManager
    Set oUserInterfaceMgr = ThisApplication.UserInterfaceManager

    On Error GoTo err
    
    Set oWindow = oUserInterfaceMgr.DockableWindows.Add("ClientID04", "InternalName04", "Sample Dockable Window")
   
    'ADD THE FORM THAT WILL POPULATE THE DOCKABLE
    'WINDOW AS A CHILD FORM HERE
    Dim f As New frmFlatPatternFix
    f.BorderStyle = fmBorderStyleNone
    f.Show
    Call oWindow.AddChild(InitMaxMin(f.Caption))
    
    ' Don't allow docking to top and bottom
    oWindow.DisabledDockingStates = kDockTop + kDockBottom
    oWindow.DockingState = kFloat

    ' Make the window visible
    oWindow.Visible = True
    oWindow.Height = 600
    oWindow.Width = 300
    
    Exit Sub
err:

oWindow.Visible = True

End Sub

I have set this to float but you can change it to whatever you need. remember, once it has been created, it will exist inside the instance on Inventor until you restart so I added an error trap to make it visible. If you stop debugging,you will need to change the ClientID and InternalName in the current instance of Inventor.

 

Hopefully this works for you (and others) as it does get around the whole hWnd issue of a userform which the solution is as follows:

 

'#64 Bit
Public Declare PtrSafe Function FindWindowA& Lib "user32" (ByVal _ lpClassName$, ByVal lpWindowName$)

'#32 Bit
'Public Declare Function FindWindowA& Lib "user32" (ByVal lpClassName$ _, 'ByVal lpWindowName$)


Sub Test()
    Dim f As New frmMyChildForm
    f.Show
    MsgBox("The hWnd is " & Get_hWnd(f.Caption))
End Sub

Public Function Get_hWnd(mCaption As String) As Long
    Dim hWnd As Long
    hWnd = FindWindowA(vbNullString, mCaption)   
    Get_hWnd = hWnd
End Function

An example of my dockable window using the above code

DockWin.png

 

 

Thanks

 

Nacho

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


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.