Open File location - within Inventor

Open File location - within Inventor

andrew_canfield
Collaborator Collaborator
2,332 Views
7 Replies
Message 1 of 8

Open File location - within Inventor

andrew_canfield
Collaborator
Collaborator

Hello

 

Thankyou for this code which will open the file location using Windows File Explorer.

How can it be tweaked to open the file location within the Inventor 'File Explorer' window*?

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

Inventor 'File Explorer' window - this one...

OpenWindow.png

Regards

 

Andrew

0 Likes
Accepted solutions (1)
2,333 Views
7 Replies
Replies (7)
Message 2 of 8

Ralf_Krieg
Advisor
Advisor
Accepted solution

Hello

 

Try this one

Sub Main()
	'Copy the path of the current model to oPath
	oPath = ThisDoc.Path
	Dim oFileDlg As Inventor.FileDialog
	Call ThisApplication.CreateFileDialog(oFileDlg)
    oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*"
    oFileDlg.FilterIndex = 1
    oFileDlg.DialogTitle = "Open File Test"
    oFileDlg.InitialDirectory = oPath
    oFileDlg.CancelError = True
    Try
    	oFileDlg.ShowOpen
		MsgBox ("File " & oFileDlg.FileName & " was selected.")
    Catch
        MsgBox ("User cancelled out of dialog")
    End Try
End Sub

R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 3 of 8

andrew_canfield
Collaborator
Collaborator
That was quick! Many Thanks
0 Likes
Message 4 of 8

andrew_canfield
Collaborator
Collaborator
Is another tweak possible?
The original request to open a folder from Inventor works faster than opening the folder in explorer but I've only found copy & paste the next useful action from the open window.
I'm thinking an ilogic rule to 'Place from current folder' would be excellent - where the current folder is where the current assembly has been saved.
0 Likes
Message 5 of 8

Ralf_Krieg
Advisor
Advisor

Hello

 

This one starts the open dialog from the folder of the current document and uses the selected part/assembly for the place component command.

 

Sub Main()
	'Copy the path of the current model to oPath
	oPath = ThisDoc.Path
	Dim oFileDlg As Inventor.FileDialog
	Call ThisApplication.CreateFileDialog(oFileDlg)
    oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*"
    oFileDlg.FilterIndex = 1
    oFileDlg.DialogTitle = "Place Component"
    oFileDlg.InitialDirectory = oPath
    oFileDlg.CancelError = True
	oFileDlg.InsertMode=True
    Try
    	oFileDlg.ShowOpen
		'MsgBox ("File " & oFileDlg.FileName & " was selected.")
		ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, oFileDlg.FileName)
		ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute
    Catch
        MsgBox ("User canceled out of dialog")
    End Try
End Sub

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 6 of 8

andrew_canfield
Collaborator
Collaborator

Amazing - thanks again.

0 Likes
Message 7 of 8

andrew_canfield
Collaborator
Collaborator
Amazing - many thanks.
0 Likes
Message 8 of 8

quangnguyenJ8ZMH
Participant
Participant

Hello @Ralf_Krieg 

thank for your code , it  works,

but i want ilogic that have scenario as below,

1, working in assembly file,

2, select a part then run ilogic and it will open folder location and we can select replaced part

3, ole part will be replaced by new part and keep the constraint.

it look like "replace" command in Inventor but i have to right click many time

by the way, in excel we can insert a macro by using record, how to use it in Inventor

many thanks

0 Likes