Author Topic: OpenFileDialog  (Read 5220 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
OpenFileDialog
« on: January 27, 2007, 11:51:45 AM »
I was trying to use this in visual lisp.
The BrowseForFolders is available like this.
Code: [Select]
    (setq sh (vla-getinterfaceobject (vlax-get-acad-object) "Shell.Application"))

    (setq folder
           (vlax-invoke-method
             sh 
             'BrowseForFolder
             0
             Message
             0
            )
    )
   
But I can't find an example of using the Windows BrowseForFiles or OpenFileDialog.
I don't have a clue as to how to use these but I though there must be a way.
What I want is the Open Files Dialog with the ability to pick more than one file.
Then return that list of files picked.
Any ideas?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

TR

  • Guest
Re: OpenFileDialog
« Reply #1 on: January 27, 2007, 11:57:06 AM »
Here's a snippet from PyACAD.NET.

Note: you need to reference System.Windows.Forms
Code: [Select]
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Python files (*.py)|*.py|All files (*.*)|*.*" ;
ofd.ShowDialog();
   

CompiledCode cc = engine.CompileFile(ofd.FileName);
cc.Execute();

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: OpenFileDialog
« Reply #2 on: January 27, 2007, 12:05:26 PM »
Thanks Tim for the quick response.
I saw several examples including this one.
Code: [Select]
Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim myStream As Stream = Nothing
    Dim openFileDialog1 As New OpenFileDialog()

    openFileDialog1.InitialDirectory = "c:\"
    openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
    openFileDialog1.FilterIndex = 2
    openFileDialog1.RestoreDirectory = True

    If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
        Try
            myStream = openFileDialog1.OpenFile()
            If (myStream IsNot Nothing) Then
                ' Insert code to read the stream here.
            End If
        Catch Ex As Exception
            MessageBox.Show("Cannot read file from disk. Original error: " & Ex.Message)
        Finally
            ' Check this again, since we need to make sure we didn't throw an exception on open.
            If (myStream IsNot Nothing) Then
                myStream.Close()
            End If
        End Try
    End If
End Sub
My problem is translating it to visual lisp and I don't understand the examples. :)
Looks like they are setting system variables rather that passing arguments to control the options.
Then calling the openFileDialog.
Gotta run some errands, will check back later today.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: OpenFileDialog
« Reply #3 on: January 27, 2007, 03:39:22 PM »
Try this http://groups.google.com/group/autodesk.autocad.customization/browse_thread/thread/28e690053dd9b1b3/851ef45c4df91092?lnk=st&q=ShowOpen%2Clisp&rnum=3&hl=en#851ef45c4df91092 (I'm not a lisper but I do know that Api's are a bit tricky)

If what lisp does is like calling an Api, then you set a group of proprties  to make tthe form show as you want it, then retrieve other properties after running it to find out what the user selected.

Below is  the vb version the Type properties for the Api GetOpenFileName
Code: [Select]
Private Type OpenFileName
    lStructSize As Long           ' Filled with UDT size
    hwndOwner As Long             ' Tied to Owner
    hInstance As Long             ' Ignored (used only by templates)
    lpstrFilter As String        ' Tied to Filter
    lpstrCustomFilter As String  ' Ignored
    nMaxCustFilter As Long       ' Ignored
    nFilterIndex As Long         ' Tied to FilterIndex
    lpstrFile As String           ' Tied to FileName
    nMaxFile As Long              ' Handled internally
    lpstrFileTitle As String     ' Tied to FileTitle
    nMaxFileTitle As Long        ' Handled internally
    lpstrInitialDir As String    ' Tied to InitDir
    lpstrTitle As String         ' Tied to DlgTitle
    flags As Long                 ' Tied to Flags
    nFileOffset As Integer       ' Ignored
    nFileExtension As Integer    ' Ignored
    lpstrDefExt As String        ' Tied to DefaultExt
    lCustData As Long             ' Ignored (needed for hooks)
    lpfnHook As Long              ' Ignored (good luck with hooks)
    lpTemplateName As Long       ' Ignored (good luck with templates)
End Type

Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" _
        (pOpenfilename As OpenFileName) As Long

Bryco

  • Water Moccasin
  • Posts: 1883
Re: OpenFileDialog
« Reply #4 on: January 27, 2007, 03:54:44 PM »
Setting flags to flags  Or  OFN_ALLOWMULTISELECT is the way to pick Multiselect.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: OpenFileDialog
« Reply #5 on: January 27, 2007, 04:46:19 PM »
Thanks for the info & the link.
Just did a search on my system  ( Windows 2000 ) for CMDLGD*.dll and found nothing.

I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

TR

  • Guest
Re: OpenFileDialog
« Reply #6 on: January 27, 2007, 04:48:26 PM »
Sorry, you posted in the .NET forum so I thought you were looking for a .NET solution.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: OpenFileDialog
« Reply #7 on: January 27, 2007, 04:57:01 PM »
Oops, sorry if I was misleading. But I want to solve it in visual lisp.
Just hit a dead end and stumbling badly on the API stuff, so I though I would try here.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: OpenFileDialog
« Reply #8 on: January 27, 2007, 06:29:21 PM »
Alan, I regularly use something like this :
Code: [Select]
    (SETQ
          FileList            (DOS_GETFILEM
                                  "Select multiple Files"
                                  "J:\\DWGS" ;; option (GETVAR "dwgprefix")
                                  "Drawing files (*.dwg)|*.dwg|All files (*.*)|*.*||"
                              )
          Path                (CAR FileList)
          FileList            (MAPCAR '(LAMBDA (x) (STRCAT Path x)) (CDR FileList))
     )

From the DosLib suite.

[edit/add:] add getvar option.
« Last Edit: January 27, 2007, 06:34:01 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: OpenFileDialog
« Reply #9 on: January 27, 2007, 06:44:35 PM »
and for some trivia, an undocumented feature is the use of an appended T flag to allow the dialog to open in detail mode.

ie

dos_getfilem "Select files" (GETVAR "dwgprefix") "Drawing files (*.dwg)|*.dwg||" T)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: OpenFileDialog
« Reply #10 on: January 27, 2007, 10:46:02 PM »
Thanks Kerry.
I was trying to avoid the need for add ons. Just thought it was possible using visual lisp & a windows method.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: OpenFileDialog
« Reply #11 on: January 28, 2007, 12:40:15 AM »
I seem to recall seeing something somewhere, but can't recall what or where

.. sorry for the pitiable assistance Alan :-)



kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: OpenFileDialog
« Reply #12 on: January 28, 2007, 09:04:34 AM »
Your efforts are never unappreciated, I thank you for that.
It's just that I wanted a specific solution.

This is the windows dialog I am after.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.