I am creating an AddIn and ran across a problem I am not sure how to solve. A text box is filled in with a code from a bar code scanner then I connect to tables to populate other information on the form based on this code. It works correctly only if there is a document open. It does not work if I have no documents open(Zero Doc). My AddIn does not reference any external documents or the active document. The text box(SCNumber) acts like it is locked when there is no document open but works as expected with an active document. Why would it matter if there is an active document?
My AddIn application type is a Class Library.
Here is the module code:
Imports System Imports Inventor Module modMain Dim CreateForm As New frmCreate 'Main function Public Sub CreateCrate() 'Show form If CreateForm IsNot Nothing AndAlso Not CreateForm.IsDisposed Then CreateForm.TopMost = True CreateForm.Show() CreateForm.BringToFront() Exit Sub End If CreateForm.Show() CreateForm.BringToFront() End Sub End Module
Here is the form code:
Imports System Imports System.Windows.Forms Imports Inventor Public Class frmCreate Private Sub frmCreate_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Me.SCNumber.Focus() Me.SCNumber.TabIndex = 0 End Sub
End Class
Solved! Go to Solution.
Hi,
I cannot tell you anything based on that description other it seems like a weird behavior... Please upload your addin project so I can have a look on my side.
Regards,
Philippe.
Philippe, I have uploaded my AddIn. Thanks for reviewing it.
If I do not have a document open, the input from the bar code scanner goes to the command alias input at the bottom of the screen instead of in the textbox on the form.
I was trying different approaches but unfortunately I cannot tell you why this is not working. The input is actually grabbed by Inventor, you can see the keys appearing in Inventor command line at the bottom, but this only happens the first time the dialog is displayed. If I close and reopen it works as expected.
It also seems specific to this dialog, if I use another dialog it works. My suggestion would be that you try creating another dialog and check step by step that the input works, you might be able to spot what going wrong this way.
I recommend that you use the window wrapper interface when displaying a child dialog. You should also migrate your UI to use ribbons instead of toolbars, it's been many moons since that old UI is deprecated. See my modified code.
Sorry for not being more helpful at the moment.
Regards,
Philippe.
Thanks Philippe. I will update the UI as you recommended. I did not see this thread before but it describes the same problem.
Changing the form to be displayed as modal seems to solve the issue.
CreateForm.Show (modeless) to CreateForm.ShowDialog (modal)
Well, I though you had a good reason to display the form as modeless. If not, you should always display it as modal, unless you want to allow user interaction with Inventor at the same time.
I do not need user interaction with Inventor so I will display it as modal. I just started writing AddIns so I was unaware of the difference between .Show and .ShowDialog.
Thanks again for your help.