How to check if other users have a file open (iLogic - No Vault)

How to check if other users have a file open (iLogic - No Vault)

Lewis.Young
Collaborator Collaborator
1,225 Views
3 Replies
Message 1 of 4

How to check if other users have a file open (iLogic - No Vault)

Lewis.Young
Collaborator
Collaborator

Hi All,

 

Just thought I'd share some code I've created which I'm sure many of you will find useful.

 

One of the caveats of using Inventor is that multiple people can open the same file, and as soon as one person saves it, nobody else will be able to save (forcing them to perform a "save as" if they want to keep their edits). This is where Vault comes into play, because it offers a check-in check-out system which prevents users from saving over each others work.

 

However, I've recently joined a company which is transitioning from AutoCAD to Inventor, but without the use of Vault yet.

So, using iLogic I've created a simple system that populates .txt files with file data, and then uses string comparisons to trigger certain actions.

 

The code is split up into 3 parts, and should be ran using iLogic external rules, with the triggers set up like this:

LewisYoung_1-1648632890350.png

 

 

oOpenFilePath - This parameter sets the location of where you want the .txt files generated. This should be a shared network location. You'll need to change this on all 3 sections of the code

 

 

The "FileCheckerAfterOpen" code will check to see if a .txt file exists. If it doesn't exist, it'll create one with the Inventor file path & name as the .txt file name, and populate the inside with your Inventor user name. If it does exist, and the user name within the .txt file doesn't match the user name of who's running the rule, a message box will prompt the user of exactly what's open and who has it open.

Imports System.IO
'-------This code is to be executed as an external rule using the event trigger "After Open Document" for "All Documents"
'-------The main purpose is to check if a different user already has a file open which you're trying to open.

oOpenFilePath = "Z:\Inventor CAD\OPEN FILES\" 'The folder where you want the placeholder txt files created
oFileName = ThisDoc.FileName(True) 'File name with extension
oFilePath = ThisDoc.Path 'The file path of the open document
oModifiedFilePath1 = oFilePath.Replace("\", "") 'The file path of the open document with no back slashes "\"
oModifiedFilePath2 = oModifiedFilePath1.Replace(":", "") 'The file path of the open document with no colons ":"
oUserName = ThisApplication.GeneralOptions.UserName 'The user name in Inventor (set in application options - general)
oTextFileName = (oOpenFilePath & oFileName & "-" & oModifiedFilePath2 & ".txt") 'The naming structure in which the txt file is created


'Check to see if txt file already exists
If System.IO.File.Exists(oTextFileName) Then
	oTxtFileText = System.IO.File.ReadAllText(oTextFileName)'Retrieve all text from the txt file
	oStringComparison = String.Compare(oUserName, oTxtFileText, True) 'Compare text to Inventor user name & file path
	

'If the text file doesn't exist, create one and populate it with your user name & file path
Else
	oWrite = System.IO.File.CreateText(oTextFileName)
	oWrite.WriteLine(oUserName)
	'oWrite.WriteLine(ThisDoc.Path)
	oWrite.Close()
End If


'If the txt file alreadys exists, and the text inside DOESN'T match the user name & file path, alert the current user of who has it open
If oStringComparison = 1 Then
	MessageBox.Show(oTxtFileText & " already has " & oFileName & " open - DO NOT SAVE", "Open File Checker")
Else
Return
End If

 

 

The "FileCheckerClose" code will check to see if a .txt file exists. If it doesn't exist the rule will finish. If it does exist, a string comparison will be performed to check whether the Inventor user running the rule matches the user name within the .txt file. If the names match, the .txt file will be deleted upon closing the document, but if they don't match the .txt file will remain.

Imports System.IO
'-------This code is to be executed as an external rule using the event trigger "Close Document" for "All Documents"
'-------It's main purpose is to delete the dummy text file if you're the person who initially opened the file. If you're not that person, the txt file will remain

oOpenFilePath = "Z:\Inventor CAD\OPEN FILES\" 'The folder where you want the placeholder txt files created
oFileName = ThisDoc.FileName(True) 'File name with extension
oFilePath = ThisDoc.Path 'The file path of the open document
oModifiedFilePath1 = oFilePath.Replace("\", "") 'The file path of the open document with no back slashes "\"
oModifiedFilePath2 = oModifiedFilePath1.Replace(":", "") 'The file path of the open document with no colons ":"
oUserName = ThisApplication.GeneralOptions.UserName 'The user name in Inventor (set in application options - general)
oTextFileName = (oOpenFilePath & oFileName & "-" & oModifiedFilePath2 & ".txt") 'The naming structure in which the txt file is created



'Check to see if txt file already exists
If System.IO.File.Exists(oTextFileName) Then
	oTxtFileText = System.IO.File.ReadAllText(oTextFileName) 'Retrieve all text from the txt file
	oStringComparison = String.Compare(oUserName & " " & ThisDoc.Path, oTxtFileText, True) 'Compare text to Inventor user name & file path
End If


'If the text inside matches the Inventor user name & file path, delete the text file
If oStringComparison = -1 Then
System.IO.File.Delete(oTextFileName)
Else
Return
End If

 

 

The "FileCheckerBeforeSave" code will check to see if a .txt file exists. If it doesn't exist the rule will finish. If it does exist, a string comparison will be performed to check whether the Inventor user running the rule matches the user name within the .txt file. If the names match, the rule will finish and allow the "FileCheckerClose" to run. If the names don't match, the document will force close and prevent the user from saving over the file.

Imports System.IO
'-------This code is to be executed as an external rule using the event trigger "Before Save Document" for "All Documents"
'-------It's main purpose is to prevent secondary users from saving over a previously opened document, by force closing when a save command is ran.

oOpenFilePath = "Z:\Inventor CAD\OPEN FILES\" 'The folder where you want the placeholder txt files created
oFileName = ThisDoc.FileName(True) 'File name with extension
oFilePath = ThisDoc.Path 'The file path of the open document
oModifiedFilePath1 = oFilePath.Replace("\", "") 'The file path of the open document with no back slashes "\"
oModifiedFilePath2 = oModifiedFilePath1.Replace(":", "") 'The file path of the open document with no colons ":"
oUserName = ThisApplication.GeneralOptions.UserName 'The user name in Inventor (set in application options - general)
oTextFileName = (oOpenFilePath & oFileName & "-" & oModifiedFilePath2 & ".txt") 'The naming structure in which the txt file is created

'Check to see if txt file already exists
If System.IO.File.Exists(oTextFileName) Then
	oTxtFileText = System.IO.File.ReadAllText(oTextFileName) 'Retrieve all text from the txt file
	oStringComparison = String.Compare(oUserName, oTxtFileText, True) 'Compare text to Inventor user name
End If

'If the text inside DOESN'T match the Inventor user name, force close the inventor file WITHOUT saving
If oStringComparison = 1 Then
ThisDoc.Document.Close(SkipSave)
Else
Return
End If

 

Lewis Young
Windows 10 Pro - 32GB Ram
Intel i7-10700k @ 3.80GHz
nVidia Quadro P2200 - 5GB
Inventor Professional 2022
3ds Max 2022
AutoCAD 2020

1,226 Views
3 Replies
Replies (3)
Message 2 of 4

mat_hijs
Collaborator
Collaborator

This seems like a good way to prevent trouble with not being able to save files someone else has already opened without Vault. Are you actually using this code already? How will this work with assemblies? Will this dirty the files?

0 Likes
Message 3 of 4

Lewis.Young
Collaborator
Collaborator

Yes I'm now running this code for all Inventor work we do!

I've tested it in a number of scenarios, but as we use it more as a team I'll probably need to add in extra failsafes and optimise it slightly.

 

When you open an assembly, every part file that's loaded within it (as well as the assembly itself) will have a corresponding .txt file generated. When you close the assembly, all of the .txt files will be deleted (unless the parts are also being used in a different open assembly). 

 

Because the rules are being ran externally, no modifications are needed for new or existing files. So no file dirtying! And the .txt files being created are only 1KB so uses very little computing power. 

 

Lewis Young
Windows 10 Pro - 32GB Ram
Intel i7-10700k @ 3.80GHz
nVidia Quadro P2200 - 5GB
Inventor Professional 2022
3ds Max 2022
AutoCAD 2020

0 Likes
Message 4 of 4

anup_harak5S8G3
Explorer
Explorer

Not working for me.
Is folder for the text file should be same as .ipt or iam file?

 

0 Likes