Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Dealing with Multiple Instances/Sessions of Inventor

2 REPLIES 2
Reply
Message 1 of 3
jdkriek
456 Views, 2 Replies

Dealing with Multiple Instances/Sessions of Inventor

I wrote this solution last year sometime for my company, but have had several requests to share it so I am. 😉

 

The correct workflow is to open directly from Inventor, but users still accidently open from Vault or from Explorer often causing another instance of Inventor. In our experience this is often a "ghost session" (not a visible tab) which can allow users to lose thier work.

 

This VBA macro is trigger by an iLogic rule set to on document save and open. It will detect the multiple instances and then alert the user. It will then attempt to close the new session automaticly.

 

Note: I have removed some features that were specific to our requirements such as:

 

- Automaticly saving results to a log file on the network

- Automaticly emailing reports of session errors to myself when users experience them

 

Tested with Inventor 2011-2013

 

Private objWMIService As Object
Private objProcess As Object
Private colProcesses As Object
Private Const cWINMGMTS As String = "winmgmts:\\" & "." & "\root\cimv2"
Public Sub SessionCheck()
'JDK 2012
'detect multiple instances
'resolve sessions
Dim Alert As Boolean
If Alert = False Then
    If isSessionErr("Inventor.exe") = True Then
        'Alert user
        MsgBox ("Session Error Detected! Attempting Auto-Fix" _
        & vbNewLine & vbNewLine & "If the problem persists please contact the Admin, Ext #XXX" _
        & vbNewLine & vbNewLine & "An email will be sent on your behalf")
        Alert = True
        'Kill new instance
        Debug.Print "Ret="; KillProcess("Inventor.exe")
        MsgBox ("Session Resolved")
        Exit Sub
    End If
End If
End Sub
Public Function KillProcess(ByVal kProcessName As String) As Boolean
Dim i As Long
i = 0
Set objWMIService = GetObject(cWINMGMTS)
Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process Where Name = '" & kProcessName & "'")
If colProcesses.count > 1 Then
    For Each objProcess In colProcesses
        i = i + 1
      If i = 2 Then
        Call objProcess.Terminate
      End If
    Next
  End If
End Function
Public Function isSessionErr(ByVal dProcessName As String) As Boolean
Set objWMIService = GetObject(cWINMGMTS)
Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process Where Name ='" & dProcessName & "'")
If colProcesses.count > 1 Then
    isSessionErr = True
Else
    isSessionErr = False
End If
End Function
Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


2 REPLIES 2
Message 2 of 3
BLHDrafting
in reply to: jdkriek

Jonathon, this comment needs clarification "open directly from Inventor". Do you mean to open files from local workspace, or from 'Open From Vault' tool in Inventor?

Brendan Henderson

Web www.blhdrafting.com.au
Twitter @BLHDrafting

Windows 7 x64 -64 GB Ram, Intel Xeon E5-1620 @ 3.6 GHz
ATI FirePro V7800 2 GB, 180 GB SSD & 1 TB HDD, Inv R2016 PDSU SP1 (Build 210), Vault 2016 Professional Update 1 (Build 21.1.4.0)
Message 3 of 3
jdkriek
in reply to: BLHDrafting


@Anonymous wrote:

Jonathon, this comment needs clarification "open directly from Inventor". Do you mean to open files from local workspace, or from 'Open From Vault' tool in Inventor?


 

Either method is fine as Inventor is seeing the file in the current session. 

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report