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?
Solved! Go to Solution.
Solved by WCrihfield. Go to Solution.
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
(Not an Autodesk Employee)
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
(Not an Autodesk Employee)
Can't find what you're looking for? Ask the community or share your knowledge.