Inventor 2013. FileDialog that does not point to current project?

Inventor 2013. FileDialog that does not point to current project?

Anonymous
Not applicable
3,837 Views
15 Replies
Message 1 of 16

Inventor 2013. FileDialog that does not point to current project?

Anonymous
Not applicable

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?

0 Likes
3,838 Views
15 Replies
Replies (15)
Message 2 of 16

Vladimir.Ananyev
Alumni
Alumni

May be this link could be useful:

http://adndevblog.typepad.com/manufacturing/2012/12/overriding-the-inventor-native-file-open-and-fil...

Cheers,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 16

Anonymous
Not applicable

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.

0 Likes
Message 4 of 16

Vladimir.Ananyev
Alumni
Alumni

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

 


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 5 of 16

Anonymous
Not applicable

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:\"

 

0 Likes
Message 6 of 16

jdkriek
Advisor
Advisor

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
Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 7 of 16

Anonymous
Not applicable

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.

0 Likes
Message 8 of 16

jdkriek
Advisor
Advisor

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
Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


0 Likes
Message 9 of 16

Anonymous
Not applicable

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

Message 10 of 16

jdkriek
Advisor
Advisor

Indeed, about 25% faster - but FSO still finds it in less than second for me 😉

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


0 Likes
Message 11 of 16

Anonymous
Not applicable

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. Smiley Wink

0 Likes
Message 12 of 16

jdkriek
Advisor
Advisor

I know exactly what you mean 😉

 

I've been slowing converting to VB.NET myself, but they keep throwing wrenches at me.

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


0 Likes
Message 13 of 16

Crstiano
Collaborator
Collaborator
Hi, Jonathan,
I have the similar problem, but in .NET VS2010

When use FileDialog, appears this Warning
Variable 'oFileDlg' is passed by reference before it has been assigned a value. A null reference exception could result at runtime.

any ideia?

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.


Cristiano Oliveira
EESignature
ConsultCAD.com

0 Likes
Message 14 of 16

Anonymous
Not applicable

Unless you post the relevant code we cannot answer the question.

0 Likes
Message 15 of 16

ekinsb
Alumni
Alumni

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)

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 16 of 16

Anonymous
Not applicable

do you mind sharing your folder error handling...

 

i have exactly the same error as you..

 

initialdirectory doesnt work for me....Smiley FrustratedSmiley Frustrated

0 Likes