Multiple Form Instances

Multiple Form Instances

NachoShaw
Advisor Advisor
468 Views
6 Replies
Message 1 of 7

Multiple Form Instances

NachoShaw
Advisor
Advisor

Hey

 

How are people managing the control / prevention of multiple instances of a form when the ribbon button is clicked for their app? doesnt matter what i do, i can load 100's of them....

 

any great tips would be well received 🙂

 

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.


0 Likes
469 Views
6 Replies
Replies (6)
Message 2 of 7

dnguyennn
Contributor
Contributor

Anyone?

0 Likes
Message 3 of 7

NachoShaw
Advisor
Advisor

Hey

 

If you're experiencing the same issue, it can be resolved in a few ways

 

you can

  • search for the process and show the form if it doesnt exist
  • make the form a dialog

I'll look at the code i use, its works just fine for me

 

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 4 of 7

dnguyennn
Contributor
Contributor

I tried couple of them, but dialog won't work in my case. Note, I am using WindowWarapper for  "press space" to work.

WindowWrapper(m_inventorApplication.MainFrameHWND)

  

If Application.OpenForms().OfType(Of Form2).Any Then
  MessageBox.Show("Opened")
Else
  Dim f2 As New Form2
  f2.Text = "form2"
  f2.Show()
End If

 

0 Likes
Message 5 of 7

NachoShaw
Advisor
Advisor

Here is my code that is called as the button is clicked before anything else runs. ProcName is the name of the process

 

Dim ProcName As String = "MyProcessName"

Dim Proc() As Process = System.Diagnostics.Process.GetProcessesByName(ProcName)
If Proc.Length <> 0 Then
    Exit Sub
End If

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 6 of 7

dnguyennn
Contributor
Contributor

I can't make it working. It got as far as "Inventor.exe" and not able to find the Form, I think because it got wrap inside Inventor.

0 Likes
Message 7 of 7

dnguyennn
Contributor
Contributor
Public Class StandardAddInServer

Implements Inventor.ApplicationAddInServer
Implements MyInterface
Private B_Form1 As Form1
...

Public Sub Activate(ByVal addInSiteObject As Inventor.ApplicationAddInSite, ByVal firstTime As Boolean) Implements Inventor.ApplicationAddInServer.Activate

m_inventorApplication = addInSiteObject.Application
m_applicationEvents = m_inventorApplication.ApplicationEvents
B_Form1 = New Form1
e_AppEvents = m_inventorApplication.FileUIEvents

...
End Sub

...
Private Sub Cmd1_OnExecute(ByVal Context As Inventor.NameValueMap) Handles Cmd1.OnExecute

    Try
       
        If B_Form1.IsDisposed = True Then
            B_Form1 = New Form1
            B_Form1.Activate()
            B_Form1.TopMost = True
            B_Form1.ShowInTaskbar = False
            B_Form1.Show(New WindowWrapper(m_inventorApplication.MainFrameHWND))
        End If

        If B_Form1.IsDisposed = False Then
            B_Form1.Activate()
            B_Form1.TopMost = True
            B_Form1.ShowInTaskbar = False
            B_Form1.Show(New WindowWrapper(m_inventorApplication.MainFrameHWND))
        End If

        
        
    Catch ex As Exception

    End Try
End Sub

 

Well, I got it working by checking Disposed for Form1.Activate() ... and it works as I want to.

0 Likes