Hi @JBerns
I think the problem is that you use ShowDialog. A dialog locks everything else up until it's closed and you never close it - you just hide it 🙂
You can set the form to topmost and make it run in the Inventor applications main frame...
Try this 🙂
AddReference "System.Drawing"
Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms
'Option Explicit On
' Pick Drawing View Test
' Rule to allow user to pick a drawing view from a dialog box
'
' Written 2020-11-17 Ver 1.0 by J. Berns
' Class to define the user form
Public Class FormClass
Inherits System.Windows.Forms.Form
' Public declarations
Public myForm As New Form
Public oDwgDoc As DrawingDocument
Public oModelDoc As Document
Public cboScale As New System.Windows.Forms.ComboBox
Public oLargeFont As System.Drawing.Font = New System.Drawing.Font("Arial", 14)
Public oSmallFont As System.Drawing.Font = New System.Drawing.Font("Arial", 8)
Public lblScale As New Label
Public btnPickView As New Button
Public btnOK As New Button
Public btnCancel As New Button
' When PickView button is clicked
Public Sub btnPickView_Click(ByVal sender As System.Object, ByVal E As System.EventArgs)
' Initialize
'' Dim oDone As Boolean = False
'' Dim oSelectView As DrawingView
'' ' Loop until NO
'' Do Until oDone = True
myForm.Hide
' ' ' CAUTION - Next line will freeze Inventor
oSelectView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Pick View")
' ' '
myForm.Show
' MyLabel = InputBox("Input label view", "Input Label View", oSelectView.Label.Text)
' oSelectView.ShowLabel = True
' oSelectView.Name = UCase(MyLabel)
'' ' More views?
'' WantSelectMore = MsgBox("Want to edit more label views?", vbYesNo, "Input More Labels")
'' If WantSelectMore = vbYes Then
'' oDone = False
'' Else
'' oDone = True
'' End If
'' Loop
End Sub
' When OK button is clicked
Public Sub btnOK_Click(ByVal sender As System.Object, ByVal E As System.EventArgs)
myForm.Close
End Sub
' When Cancel button is clicked
Public Sub btnCancel_Click(ByVal sender As System.Object, ByVal E As System.EventArgs)
myForm.Close
End Sub
Public Sub IntializeUserForm
' Build the scale list
Dim ScaleList() As String = New String() {"SEE VIEW SCALE", _
"1"" = 1""", "3/4"" = 1""", "1/2"" = 1""", "1/4"" = 1""", "1/8"" = 1""", _
"1"" = 1'", "3/4"" = 1'", "1/2"" = 1'", "3/8"" = 1'", "1/4"" = 1'", "3/16"" = 1'", "1/8"" = 1'" }
'' Comboboxes and Textboxes
' Scale
lblScale = New Label
With lblScale
.Name = "lblScale"
.Location = New System.Drawing.Point(10, 20)
.Size = New System.Drawing.Size(100, 30)
.Font = oLargeFont
.Text = "SCALE:"
End With
' cboScale = New ComboBox
With cboScale
.Name = "cboScale"
.Location = New System.Drawing.Point(10, 50)
.Items.AddRange(ScaleList)
.Size = New System.Drawing.Size(230, 30)
.Font = oLargeFont
End With
'' BUTTONS
btnPickView = New Button
With btnPickView
.Name = "btnPickView"
.Location = New System.Drawing.Point(160, 25)
.Width = 80
.Height = 20
.Font = oSmallFont
.Text = "Pick View"
AddHandler.Click, AddressOf btnPickView_Click
End With
btnOK = New Button
With btnOK
.Name = "btnOK"
.Location = New System.Drawing.Point(20, 100)
.Width = 100
.Height = 30
.Font = oLargeFont
.Text = "OK"
AddHandler.Click, AddressOf btnOK_Click
End With
btnCancel = New Button
With btnCancel
.Name = "btnCancel"
.Location = New System.Drawing.Point(135, 100)
.Width = 100
.Height = 30
.Font = oLargeFont
.Text = "Cancel"
AddHandler.Click, AddressOf btnCancel_Click
End With
' Format the UserForm
With myForm
' Set up form
.FormBorderStyle = FormBorderStyle.FixedToolWindow
.StartPosition = FormStartPosition.CenterScreen
.Width = 270
.Height = 190
.TopMost = True
.Text = "Pick Drawing View Test"
.Name = "PickDrawingViewTest"
.IsMdiContainer = False
' Add controls
'' Labels
.Controls.Add(lblScale)
'' Edit boxes
.Controls.Add(cboScale)
'' Buttons
.Controls.Add(btnPickView)
.Controls.Add(btnOK)
.Controls.Add(btnCancel)
End With
End Sub
Public Sub Main()
' Verify that the active document is a drawing, notify otherwise
If ThisApplication.ActiveDocument.DocumentType = kDrawingDocumentObject Then
' Get the active document
oDwgDoc = ThisApplication.ActiveDocument
' Initialize the user form
IntializeUserForm
myForm.TopMost = True
Dim wrapper = New HwndWrapper(ThisApplication.MainFrameHWND)
' Display the form
myForm.Show(wrapper)
' Update document
InventorVb.DocumentUpdate()
Else
MessageBox.Show("Please run this routine from a drawing file.", _
"WARNING", _
MessageBoxButtons.OK, MessageBoxIcon.Warning _
)
Exit Sub
End If
End Sub
End Class
Class HwndWrapper
Implements IWin32Window
Private ReadOnly m_hWnd As IntPtr
Public Sub New(ByVal hWnd As IntPtr)
m_hWnd = hWnd
End Sub
Public Sub New(ByVal hWnd As Integer)
m_hWnd = CType(hWnd, IntPtr)
End Sub
Public ReadOnly Property Handle As IntPtr Implements IWin32Window.Handle
Get
Return m_hWnd
End Get
End Property
End Class