Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Very Basic open file dialogue with initial directory

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
e2000773
241 Views, 4 Replies

Very Basic open file dialogue with initial directory

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?

4 REPLIES 4
Message 2 of 5
WCrihfield
in reply to: e2000773

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 5
e2000773
in reply to: WCrihfield

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

Message 4 of 5
WCrihfield
in reply to: e2000773

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 5
e2000773
in reply to: WCrihfield

It certainly did! Thank you so much!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report