File Dialog for folder selection

File Dialog for folder selection

Anonymous
Not applicable
5,910 Views
10 Replies
Message 1 of 11

File Dialog for folder selection

Anonymous
Not applicable

I want to use the inventor file dialog to allow the user to navigate to select a folder. 

 

I know I could use a windows folder dialog, but I prefer the interface of the file dialog. 

 

You can do this using the windows file dialog by using a filter of "*.none" and then extracting the directory from the filename once the dialog "open" is pressed:

 

 

Using obj As New Windows.Forms.OpenFileDialog
obj.Filter = "Directories|*.none"
obj.CheckFileExists = False
obj.CheckPathExists = False
obj.InitialDirectory = startPath
obj.Title = "Select Save Directory"
obj.FileName = "Save Directory"
If obj.ShowDialog = Windows.Forms.DialogResult.OK Then
savePath = IO.Directory.GetParent(obj.FileName).FullName


'can extract directory from savePath

End If
End Using

 

Is there a way to do this with the inventor file dialog? I'd prefer to use the inventor file dialog because it already includes links to the work space and thumbnails etc.

 

Thanks

0 Likes
Accepted solutions (4)
5,911 Views
10 Replies
Replies (10)
Message 2 of 11

Jesper_S
Collaborator
Collaborator

Hi.

 

I'm not a master coder in iLogic but found this some time ago here in the forum.

 

Dim oFileDlg As inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
'oFileDlg.InitialDirectory = sPath 'currently doesn't work
oFileDlg.CancelError = True
oFileDlg.MultiSelectEnabled = True
'oFileDlg.ShowQuickLaunch = True
' Define the filter to select files 
oFileDlg.Filter = "Inventor Drawing Files (*.idw;*.dwg)|*.idw;*.dwg"
' Set the title for the dialog.
oFileDlg.DialogTitle = "Choose the files to work with."

On Error Resume Next
'oFileDlg.ShowSave()
oFileDlg.ShowOpen()
If Err.Number <> 0 Then
Return
ElseIf oFileDlg.FileName <> "" Then
selectedfiles = oFileDlg.FileName
End If

Hope you can use some of it. 

 

//Jesper


//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
0 Likes
Message 3 of 11

Anonymous
Not applicable

Thanks Jesper, but that is not quite what I am after. 

 

That is to open or save a file, I would like to use the same dialog however just to get the folder not a file. 

 

0 Likes
Message 4 of 11

Sergio.D.Suárez
Mentor
Mentor
Accepted solution
Imports System.Windows.Forms
' Toma la ruta del archivo activo Dim RutaExport As String = ThisDoc.Path ' Define el cuadro de dialogo de busqueda de carpeta Dim Dialog = New FolderBrowserDialog() ' Establece opciones del cuadro de dialogo Dialog.SelectedPath = RutaExport Dialog.ShowNewFolderButton = True Dialog.Description = "Elige la carpeta de exportación" ' muestra el cuadro de dialogo If DialogResult.OK = Dialog.ShowDialog() Then ' captura la ruta de exportacion seleccionada RutaExport = Dialog.SelectedPath & "\"

MessageBox.Show(RutaExport, "Title")

late but sure, try this code greetings


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 5 of 11

Anonymous
Not applicable
Accepted solution

Try this one:

Function BrowseForFolder(Optional OpenAt As Variant) As Variant
     'Function purpose:  To Browser for a user selected folder.
     'If the "OpenAt" path is provided, open the browser at that directory
     'NOTE:  If invalid, it will open at the Desktop level

    Dim ShellApp As Object

     'Create a file browser window at the default folder
    Set ShellApp = CreateObject("Shell.Application"). _
    BrowseForFolder(0, "Please choose a folder", 0, OpenAt)
     
    If ShellApp Is Nothing Then
        BrowseForFolder = ""
        Exit Function
    End If
     
     'Set the folder to that selected.  (On error in case cancelled)
    On Error Resume Next
    BrowseForFolder = ShellApp.self.Path
    On Error GoTo 0

     'Destroy the Shell Application
    Set ShellApp = Nothing

     'Check for invalid or non-entries and send to the Invalid error
     'handler if found
     'Valid selections can begin L: (where L is a letter) or
     '\\ (as in \\servername\sharename.  All others are invalid
    Select Case Mid(BrowseForFolder, 2, 1)
    Case Is = ":"
        If Left(BrowseForFolder, 1) = ":" Then GoTo Invalid
    Case Is = "\"
        If Not Left(BrowseForFolder, 1) = "\" Then GoTo Invalid
    Case Else
        GoTo Invalid
    End Select

    Exit Function

Invalid:
     'If it was determined that the selection was invalid, set to False
    BrowseForFolder = False
End Function
Message 6 of 11

skatzY7HV8
Enthusiast
Enthusiast

Did this question ever get answered? I tried the code in the latest post and it still gives the unfriendly windows folder browser

0 Likes
Message 7 of 11

Curtis_Waguespack
Consultant
Consultant

Hi @skatzY7HV8 

 

This would be rather clunky, but you could have the user select a file, and just get the parent directory of that file, as in this example. Otherwise I don't know of a way, other than to use the "unfriendly" version to browse for a folder.

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Imports System.Windows.Forms
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
'oFileDlg.InitialDirectory = sPath 'currently doesn't work
oFileDlg.CancelError = True
oFileDlg.MultiSelectEnabled = True
'oFileDlg.ShowQuickLaunch = True
' Define the filter to select files 
oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*"
' Set the title for the dialog.
oFileDlg.DialogTitle = "Choose a file in the folder you are trying to get."

On Error Resume Next
'oFileDlg.ShowSave()
oFileDlg.ShowOpen()
If Err.Number <> 0 Then
Return
ElseIf oFileDlg.FileName <> "" Then
oFolder = System.IO.Path.GetDirectoryName(oFileDlg.FileName)
End If

MsgBox(oFolder)

 

 

EESignature

0 Likes
Message 8 of 11

skatzY7HV8
Enthusiast
Enthusiast

Curtis,

 

Thanks for the reply - that will work for me as a faster method allowing shortcuts to be used. Maybe one day there will be a better select folder dialog out of the box.

 

Thanks

 

Stephen

0 Likes
Message 9 of 11

dvinalsauc
Explorer
Explorer
Accepted solution
buen codigo amigo. Solo te falto el End If.
Una pregunta, sabrias como hacer un codigo para insertar un assembly o part desde un Browse Windows? Lo que normalmente haria con un simple PLACE, pero quiero agregar unas cuantas funciones
Message 10 of 11

william
Advocate
Advocate
Accepted solution

Hi, I was looking for this recently and found the below to work quite well. 

OpenAt = "your starting location"
Dim dialog = New FolderBrowserDialog()
dialog.SelectedPath = OpenAt
If DialogResult.OK = dialog.ShowDialog() Then
	MessageBox.Show(dialog.SelectedPath, "Title")
End If

 

Message 11 of 11

tim11_manhhieu
Advocate
Advocate

thank you so much.

0 Likes