Initialdirectory does not function with ShowOpen

Initialdirectory does not function with ShowOpen

TONELLAL
Collaborator Collaborator
990 Views
9 Replies
Message 1 of 10

Initialdirectory does not function with ShowOpen

TONELLAL
Collaborator
Collaborator

All is in the subject !

In 2007, this was identified as "High priority issue" : https://forums.autodesk.com/t5/inventor-customization/iv2008-sp1-ofiledialog-showsave-does-not-hono...

In Inv 2009, it was not solved.

In Inv 2010, it was announced to be solved, but not... : https://forums.autodesk.com/t5/inventor-customization/vba-filedialog-object-problem-with-initialdire...

In 2017, Autodesk is still working on it... : https://forums.autodesk.com/t5/inventor-customization/file-dialog-initial-directory-stuck-on-workspa...

 

Can we expect it will be solved one day ?

 

PS : Sorry, I had not seen that it had only been more than 10 years since this had been identified as a "high priority issue".

 

0 Likes
Accepted solutions (1)
991 Views
9 Replies
Replies (9)
Message 2 of 10

chandra.shekar.g
Autodesk Support
Autodesk Support

@TONELLAL,

 

As mentioned in the below forum discussion, FileDialog.InitialDirectory is ignored if assembly or part is open. If no document is opened and try to run below code, it recognizes mentioned directory as InitialDirectory.

 

https://forums.autodesk.com/t5/inventor-customization/file-dialog-initial-directory-stuck-on-workspa...

Public Sub CreateFileDialog()

    Dim dlg As FileDialog
    Call ThisApplication.CreateFileDialog(dlg)
    
    dlg.InitialDirectory = "C:\Temp"
    dlg.Filter = "Inventor Files (*.ipt)|*.ipt | Assembly File (*.iam)|*.iam"
    dlg.DialogTitle = "Save Native"
    
    Call dlg.ShowOpen

End Sub		

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 3 of 10

TONELLAL
Collaborator
Collaborator

The problem is I work on a file, so mandatory open, and in the workflow I need to open a config file (not Inventor file). Do you have a workaround in this case ? And when do you think the problem will be solved ?

0 Likes
Message 4 of 10

YuhanZhang
Autodesk
Autodesk

Can you let me which Inventor build do you use, and provide a snippet of VBA code to reproduce the problem? From your description you want to open a non-Inventor file when some document is open already, so can you try below VBA code if it works there(make sure to change the InitialDirectory) :

 

Sub TestFileDialogSample()
 ' 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 = "Config Files (*.xml)|*.xml"
 oFileDlg.InsertMode = False

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

 ' Show the open dialog.
 oFileDlg.ShowOpen
 End Sub


If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 5 of 10

TONELLAL
Collaborator
Collaborator

Here's the code I use :

Sub test()

Dim oFileDlg As FileDialog
Set oFileDlg = Nothing

templatesPath = ThisApplication.DesignProjectManager.ActiveDesignProject.templatesPath

Call ThisApplication.CreateFileDialog(oFileDlg)

oFileDlg.DialogTitle = "Save config file"
oFileDlg.Filter = "XML Files (*.xml)|*.xml"
oFileDlg.InitialDirectory = templatesPath
oFileDlg.CancelError = True
oFileDlg.InsertMode = False
'oFileDlg.ShowSave
oFileDlg.ShowOpen

End Sub

It works fine since I added "oFileDlg.InsertMode = False".

Now I have the same problem with ShowSave... InsertMode does nothing in this case ...

Since the dialog box itself does nothing, is it possible to use ShowOpen only to display a dialog box, but to save the file after ? What is the différence between ShowSave and ShowOpen ?

Inventor I use is 2016.2.3 build 236

0 Likes
Message 6 of 10

chandra.shekar.g
Autodesk Support
Autodesk Support

@TONELLAL,

 

oFileDlg.InsertMode Property is related to ShowOpen method. For more details, go through below Inventor API documentation link.

 

http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-CA065814-A0F7-429D-A097-8E14D71D6C56

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 7 of 10

YuhanZhang
Autodesk
Autodesk
Accepted solution

So the ShowOpen works fine there. The ShowOpen and ShowSave will display the dialog with different caption and use the Open dialog for Save would confuse users. A workaround now for the ShowSave is to specify the FileName property with a default filename for it, then it will direct to the folder you specify, try below VBA sample and let me if it is acceptable:

 

Sub TestFileDialogSample()
 ' Create a new FileDialog object.
 Dim oFileDlg As FileDialog
 Call ThisApplication.CreateFileDialog(oFileDlg)

 ' Define the filter for file type.
 oFileDlg.Filter = "Config Files (*.xml)|*.xml"

 ' Save the file to the C:\Temp\ and set a default name for it.
 oFileDlg.FileName = "C:\Temp\DefaultFileName"
 
 ' Show the save dialog.
 oFileDlg.ShowSave
 End Sub


If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 8 of 10

TONELLAL
Collaborator
Collaborator

Ok, it functions !

Thanks,

 

Alain

0 Likes
Message 9 of 10

YuhanZhang
Autodesk
Autodesk

Thanks for the feedback.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 10 of 10

RoyWickrama_RWEI
Advisor
Advisor

Your posting helped me to get around my issue I had in my other posting. Thanks.

0 Likes