Very Basic open file dialogue with initial directory

Very Basic open file dialogue with initial directory

e2000773
Enthusiast Enthusiast
724 Views
5 Replies
Message 1 of 6

Very Basic open file dialogue with initial directory

e2000773
Enthusiast
Enthusiast

Hey I can't seem to get this code to work:

'Create File Open Dialogue oDoc = ThisDoc.Document Dim oFileDlg As Inventor.FileDialog = Nothing

InventorVb.Application.CreateFileDialog(oFileDlg)

oFileDlg.Filter = "Part Files (*.ipt)|*.ipt"

'Set open location :

oFileDlg.InitialDirectory = "C:\Users\Name\Desktop\"

'Show File Open Dialogue

oFileDlg.DialogTitle = "Open a Part File" oFileDlg.ShowOpen() PartName = oFileDlg.FileName If PartName = "" Then : Return : End If

It works perfectly until you choose a file and it doesn't open anything in Inventor (empty). The initial directory is important for me so I can make a form with parameters changing then initial directory location. I got a similar thing working in
assembly file, but to get it to work in a part file is a problem. Am I missing some line of code or?

0 Likes
Accepted solutions (1)
725 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Hi @e2000773.  Is that all of the code?  It doesn't appear to have anything at the end to handle when an actual file name is returned, rather than an empty String.  That Inventor.FileDialog doesn't actually Open or Save any file, it will just return the FullFileName (or multiple FullFileName Strings, if option enabled) of the file(s) you selected within it.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 6

e2000773
Enthusiast
Enthusiast

It’s all the code I have. I don’t know what needs to be added. 

0 Likes
Message 4 of 6

WCrihfield
Mentor
Mentor
Accepted solution

Here is a working example, using your code as a starter.  After the file selection part is done, it captures the FullFileName of the selected file to the PartName variable, then uses that to open that specified document.  Then it shows you the FullFileName of the now opened part file (should be the same value as the PartName variable).

'Create File Open Dialogue
Dim oFileDlg As Inventor.FileDialog = Nothing
ThisApplication.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Part Files (*.ipt)|*.ipt"
'Set open location :
oFileDlg.InitialDirectory = "C:\Users\Name\Desktop\"
oFileDlg.DialogTitle = "Open a Part File"
'Show File Open Dialogue
 oFileDlg.ShowOpen() 'may throw Error if canceled
 PartName = oFileDlg.FileName
 If PartName = "" Then Return 'exits the rule
Dim oOpenedDoc As Document = ThisApplication.Documents.Open(PartName, True) 'True = Visible
MsgBox("oOpenedDoc.FullFileName = " & oOpenedDoc.FullFileName, , "")

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 6

e2000773
Enthusiast
Enthusiast

It certainly did! Thank you so much!

0 Likes
Message 6 of 6

Silvia.van.Emmerik
Advocate
Advocate

Thanks!

It didn't work at first because I had an initialDirectory outside my project. When I clicked the Open button the DialogBox just wouldn't close. Turned out there was some hidden message.

I had to add this line to get it working:

oFileDlg.SuppressResolutionWarnings = True

 

0 Likes