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: 

VBA FileDialog object - problem with InitialDirectory

24 REPLIES 24
Reply
Message 1 of 25
liborb
2216 Views, 24 Replies

VBA FileDialog object - problem with InitialDirectory

I need (in VBA makro) save file to given folder.
I want to do it with FileDialog object but I can't set folder in dialog windows with InitialDirectory method.
There is always last used folder in dialog window.
Does anybody know why InitialDirectory doesn't work?

{code}
Call ThisApplication.CreateFileDialog(oFileDlg)
oFileDlg.InitialDirectory = "C:\temp"
oFileDlg.ShowSave
{code}
24 REPLIES 24
Message 2 of 25
ENDCad
in reply to: liborb

I have the same problem. And it is odd becuase it is only with the Save, the Open works fine.

For me the Save always goes to my default inventor last save directory.

Any input would be appreciated.
Message 3 of 25
Anonymous
in reply to: liborb

Could you let me know which version of Inventor (and service pack) each of
you is seeing this issue with?

thanks,
Sanjay-
Message 4 of 25
liborb
in reply to: liborb

I use Inventor 2009, SP 2 but now I found solution.
Path must be written in FileName attribut
{code}
Call ThisApplication.CreateFileDialog(oFileDlg)
oFileDlg.InitialDirectory = 'C:\temp'
oFileDlg.FileName = 'C:\temp\example.ipt'
oFileDlg.ShowSave
{code}
Message 5 of 25
ENDCad
in reply to: liborb

Inventor 2009 Service Pack 1
(didn't know 2 was out ill have to update)

That filename trick worked my only problem is that it fills the Filename property which is what i use to check for valid selections. ill be able to work around that though in my error checking to prevent a million copies of that default name being created.

thanks

EDIT:
i used this code since my initial directory changes from time to time....

{code}

newPath.DialogTitle = "Select Location for New File"
newPath.InitialDirectory = ThisApplication.FileLocations.Workspace
newPath.FileName = newPath.InitialDirectory + "\.dwg"
newPath.CancelError = True

{code}

this allows an invalid save with an error and doesn't default your directory to one spot. Edited by: ENDCad on Sep 9, 2009 4:02 PM
Message 6 of 25
Anonymous
in reply to: liborb

I checked and unfortunately, this was a known issue in Inventor 2009.
Providing the full path in the filename is the only workaround, as you've
discovered. This issue is fixed in Inventor 2010 and doesn't need a filename
specification.

Sanjay-
Message 7 of 25
bjogo
in reply to: liborb



Sanjay wrote:

I checked and unfortunately, this was a known issue in Inventor 2009.

Providing the full path in the filename is the only workaround, as you've

discovered. This issue is fixed in Inventor 2010 and doesn't need a filename

specification.



Sanjay,



I am a user of Inventor 2010 SP1 and unfortunately this issue is NOT solved yet!!!!!!!!!!!!!!
I have the same problems with the "Initial Directory"

How can i solve this?

thx

bjorn
Message 8 of 25
noontz
in reply to: Anonymous

2013 & it seems this thing is still sneaking around.. or???

 

Message 9 of 25
philippe.leefsma
in reply to: noontz

Hi,

 

I'm testing that under 2013 SP1.1 Update 2 and it seems to work correctly:

 

Public Sub CreateFileDialog()

    Dim App As Inventor.Application
    Set App = ThisApplication
    
    Dim dlg As FileDialog
    Call App.CreateFileDialog(dlg)
    
    dlg.InitialDirectory = "C:\"
    dlg.filter = "Inventor Files (*.ipt)|*.ipt | Assembly File (*.iam)|*.iam"
    dlg.DialogTitle = "Save Native"
    
    dlg.ShowSave

End Sub

Regards,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 10 of 25
noontz
in reply to: philippe.leefsma

Doesn´t work for me in C# & when I copy paste your code directly in the VBA editor  & run I end up in my vault project folder..  e.g. not C:\".  I´m on the same build.

Message 11 of 25
xiaodong_liang
in reply to: noontz

Hi,

 

there is a C# demo code in the API help reference. Hope it helps you to figure out the problem:

 

public void TestFileDialog()
{
    Application oApp = ThisApplication;

    // Create a new FileDialog object.
    FileDialog oFileDlg;
    oApp.CreateFileDialog(out(oFileDlg));

    // Define the filter to select part and assembly files or any file.
    oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*";

    // Define the part and assembly files filter to be the default filter.
    oFileDlg.FilterIndex = 1;

    // Set the title for the dialog.
    oFileDlg.DialogTitle = "Open File Test";

    // Set the initial directory that will be displayed in the dialog.
    oFileDlg.InitialDirectory = "C:/Temp";

    // Set the flag so an error will not be raised if the user clicks the Cancel button.
    oFileDlg.CancelError = false;

    // Show the open dialog.  The same procedure is also used for the Save dialog.
    // The commented code can be used for the Save dialog.
    oFileDlg.ShowOpen();
    // oFileDlg.ShowSave();

    System.Windows.Forms.MessageBox.Show("File " + oFileDlg.FileName + " was selected.", "Selected file");

}
 

 

Message 12 of 25
noontz
in reply to: xiaodong_liang

Yep.. That´s more or less the same code I used, but no cigar as mentioned earlier, Using the IV2009 workaround described in this thread, does the job so I´m long gone. I have a strong feeling the internal vaultclient is overriding oFileDlg.InitialDirectory.. Check it out  😉

Message 13 of 25
ZX_Spectrum_48k
in reply to: noontz

Workaround described in this thread doesn't work for an open file dialog. Anybody got a work around for an open file dialog? or an alternative method of calling an open file dialog box where the initial directory can be set?? 

 

Thx in advance

Message 14 of 25

Hi ZX_Spectrum_48k ,

 

could you clarify what kind of problem you hit? I did not get a clue from the existing messages in the thread.

Message 15 of 25

Hi,

The sample code in the 2014 help menu as reproduced below will not produce a file dialog box starting in c:\temp, instead the file dialog will display the last used folder.
Seems to have been an issue for a while ......................


Public Sub TestFileDialog() ' Create a new FileDialog object. Dim oFileDlg As FileDialog Call ThisApplication.CreateFileDialog(oFileDlg) ' Define the filter to select part and assembly files or any file. oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*" ' Define the part and assembly files filter to be the default filter. oFileDlg.FilterIndex = 1 ' Set the title for the dialog. oFileDlg.DialogTitle = "Open File Test" ' Set the initial directory that will be displayed in the dialog. oFileDlg.InitialDirectory = "C:\Temp" ' Set the flag so an error will be raised if the user clicks the Cancel button. oFileDlg.CancelError = True ' Show the open dialog. The same procedure is also used for the Save dialog. ' The commented code can be used for the Save dialog. On Error Resume Next oFileDlg.ShowOpen ' oFileDlg.ShowSave ' If an error was raised, the user clicked cancel, otherwise display the filename. If Err Then MsgBox "User cancelled out of dialog" ElseIf oFileDlg.FileName <> "" Then MsgBox "File " & oFileDlg.FileName & " was selected." End If End Sub
Message 16 of 25
adam.nagy
in reply to: ZX_Spectrum_48k

Hi,

 

Strange. It seems to work for me and starts in whatever folder I set as InitialDirectory: http://www.screencast.com/t/w2K7yJ9q

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 17 of 25
jdkriek
in reply to: adam.nagy

*Make sure the directory actually exists and you have proper permissions*

 

 We had this issue recently and discovered if the directory doesn't exist it will simply use the last directory it succesfully hit.

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 18 of 25
ZX_Spectrum_48k
in reply to: jdkriek

 

*Make sure the directory actually exists and you have proper permissions*

 

Don't think thats the problem - I can get initial directory to behave if I have no inventor files open.

As soon as I have an inventor file open, always get the project folder regardless of what initial directory is set to.

Anyone else find the same thing??

Message 19 of 25
binuvarkey
in reply to: xiaodong_liang

We have the same problem in all 4 seats of Inventor Pro 2014.

oFileDlg.InitialDirectory settings are not honoured and the dialog opens with Workspace in focus. We have Vault 2014 Workgroup installed and signed in.

Message 20 of 25
binuvarkey
in reply to: binuvarkey

When the dialog opens in the Project Folder, if we browse to another directory from the dialog box and cancel the dialog or open the file, next time initialdirectory is set to the other directory we browsed to or opened file from.

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

Post to forums  

Autodesk Design & Make Report