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
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?
@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.