I'd like to create a filedialog that points to the IntitialDirectory property location. Not the current project.
It doesn't look like the filedialog object uses the InitialDirectory property at all. Anyway to fix it?
May be this link could be useful:
Cheers,
1) I am using VBA here not VB.NET. So the first suggestion of your link does not apply.
2) The second suggestioin basically says to use the InitialDirectory property of the inventor openfiledialog.
This as I said previously appears to be broken.
I use to use the WinAPI to launch File and Folder broswer dialogs. I cannot get them to work with 64 bit VBA 7.
It would be nice if someone from Autodesk posted them for that envioronment. I have managed to get
all my other WinAPI tools working by using ptrsafe, longlong, and ptrlong, but not the above.
I made a workaround by creating an Addin in VB.NET that exposes file and folder browsing dialogs.
I call them from VBA. Seems rediculous to me I have to go to such lengths.
InitialDirectory property allows you set any directory that will be used when the dialog is initially displayed.
WorkspacePath property of the DesignProject object is useful if you need to open the current workspace.
Here is VBA sample:
Public Sub TestFileDialog() ' Set a reference to the DesignProjectManager object. Dim oDesignProjectMgr As DesignProjectManager Set oDesignProjectMgr = ThisApplication.DesignProjectManager 'current workspace path Dim sPath As String sPath = oDesignProjectMgr.ActiveDesignProject.WorkspacePath ' 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 = sPath '"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
I do not think you are hearing me.
I know how to use the inventor file dialog. Been using it for years.
I do not want the workspace path.
I am not trying to load inventor files.
In 2013 when I set the InitialDirectory property to "C:\" is opens a the last used inventor path not "C:\"
This works fine for me in 2013:
oFileDlg.InitialDirectory = "C:\"
....
Public Sub TestFileDialog() Dim oFileDlg As FileDialog Call ThisApplication.CreateFileDialog(oFileDlg) oFileDlg.Filter = "All Files (*.*)" oFileDlg.DialogTitle = "Open File Test" oFileDlg.InitialDirectory = "C:\" oFileDlg.CancelError = True On Error Resume Next oFileDlg.ShowOpen If Err Then MsgBox "User cancel" ElseIf oFileDlg.FileName <> "" Then MsgBox "File " & oFileDlg.FileName & " was selected." End If End Sub
Ahhhhh!
Discovered the issue. Due to a network error my desired initialDirectory was not available.
The problem is that the Inventor File Dialog does not error out when given a bad initial directory.
It just defaults to the last used.directory.
I can work around this by checking for the folder (with error handling) before I use the dilaog.
Still I find the filedialog behaviour odd ball.
Bingo!
Public Sub TestFileDialog() ' Include REF to Microsoft Scripting Runtime Dim FSO As New Scripting.FileSystemObject Dim Path As String Path = "C:\path\" If FSO.FolderExists(Path) Then ' Continue Else MsgBox ("Folder Does Not Exist") Exit Sub End If Dim oFileDlg As FileDialog Call ThisApplication.CreateFileDialog(oFileDlg) With oFileDlg .Filter = "All Files (*.*)" .DialogTitle = "Open File Test" .InitialDirectory = Path .CancelError = True End With On Error Resume Next oFileDlg.ShowOpen If Err Then MsgBox "User cancel" ElseIf oFileDlg.FileName <> "" Then MsgBox ("File " & oFileDlg.FileName & " was selected") End If End Sub
Personally I do not like the FileSystemObject.for VBA.
Way slow and bloated.
For file and folder checks I use the following two functions.
Many orders of magnitude faster than Dir$() or FSO.when
looping.
Public Function FileExists(ByVal sFilename As String) As Boolean
Dim att As Long
On Error Resume Next
att = GetAttr(sFilename)
If Err.Number = 0 Then
FileExists = True
Else
Err.Clear
FileExists = False
End If
On Error GoTo 0
End Function
'---
Public Function FolderExists(ByVal sFolderName As String) As Boolean
Dim att As Long
On Error Resume Next
att = GetAttr(sFolderName)
If Err.Number = 0 Then
FolderExists = True
Else
Err.Clear
FolderExists = False
End If
On Error GoTo 0
End Function
Agreed. As I have to support a large group of users I prefer to have a few object reference dependencies as possible. This is only with VBA though. Not a problem with compiled apps. If things ever settle down I plan to port everything to VB.NET or C#. Of course they haven't settled down for that last ten years.
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
The following code will result in the warning you listed.
Dim fDialog As Inventor.FileDialog invApp.CreateFileDialog(fDialog)
Initializing the variable, as shown below, will get rid of the warning.
Dim fDialog As Inventor.FileDialog = Nothing invApp.CreateFileDialog(fDialog)
do you mind sharing your folder error handling...
i have exactly the same error as you..
initialdirectory doesnt work for me....