iLogic – Open File Location

@ClintBrown3D Autodesk Inventor ilogic - open file location

This is more of a quick tip than a blog post, but it’s certainly worth sharing, as it may save you some time. Have you ever wanted to open the location of the file you are working on?

I was about to publish this blog post, when I got an email from my regular guest blog poster M Veldkamp, he had a new blog idea, and it turned out to be exactly the same idea I was about to publish. The difference being that this version was solved slightly differently. So this post is a collaboration of sorts, as we decided to share both of our approaches to solving the same basic problem.

Here’s my iLogic code to open the current Inventor document’s folder, using the Windows “Shell” command.  I have included more information on using “Shell” Commands at the bottom of this post :

Shell("explorer.exe " & ThisDoc.Path, vbNormalFocus)

Here’s M Veldkamp’s method, there is a version of this code at the bottom with comments to make it easier to follow:

Sub Main()
	oPath = ThisDoc.Path
	Dim Proc As String = "Explorer.exe"
	Dim Args As String = ControlChars.Quote & oPath & ControlChars.Quote
	Process.Start(Proc, Args)
End Sub

Shell Commands:

To give a bit more context and to make this post a more useful, I have included a few more details around other Windows apps that can be run using the “Shell” command, as well as some detail around the “AppWinStyle”.

The iLogic rule below will open up the folder that the current Inventor file resides in (in Windows Explorer). As mentioned, there are a few additional bits included in the iLogic code below, which will hopefully make this even more useful.

'iLogic Rule by @ClintBrown3D
'Originally posted here: https://clintbrown.co.uk/ilogic_file_location

Shell("explorer.exe " & ThisDoc.Path, vbNormalFocus) 

'Below are a few other windows applications that work with the Shell Command, see the Window behaviour or "AppWinStyle" details below 

'Shell("Calc.exe", vbNormalFocus)
'Shell("cmd.exe", vbNormalFocus)
'Shell("explorer.exe", vbNormalFocus)
'Shell("msinfo32.exe", vbNormalFocus)
'Shell("mspaint.exe", vbNormalFocus)
'Shell("cmd.exe",vbMaximizedFocus)

'Additional details From Microsoft:
'https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualbasic.appwinstyle?view=netframework-4.8
'vbMaximizedFocus = Window is maximized with focus.
'vbNormalFocus = Window has focus And Is restored To its original size And position.
'vbMinimizedFocus = Window Is displayed As an icon With focus.
'vbNormalNoFocus = Window Is restored To its most recent size And position. The currently active window remains active

Commented version of M. Veldkamp’s iLogic Code:

Sub Main()
	'Copy the path of the current model to oPath
	oPath = ThisDoc.Path
	'[Now we want to open this path with Explorer.exe. We can use the Process.Start function for this.
	'The Start function needs to know which application it'll launch and what arguments it requires. 
	']oPath is already a string but the Start function needs this: [Start(Explorer.exe "C:/Filepath/")]
	Dim Proc As String = "Explorer.exe"
	Dim Args As String = ControlChars.Quote & oPath & ControlChars.Quote
	Process.Start(Proc, Args)
End Sub

Hopefully we’ve shown you that not everything that you automate has to be a difficult problem, and that there is always more than one approach to a problem. We also encourage you to comment down below and share how you’ve solved something simple, but that saves you time.