See the top rated post in this thread. Click here

Results 1 to 2 of 2

Thread: File Multi Selection Dialog (and Folder Select)

  1. #1
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,126
    Login to Give a bone
    1

    Default File Multi Selection Dialog (and Folder Select)

    Hey Group,

    While I was playing around with the folder selection routines I started playing around with a multi select file dialog box functions.

    In LISP the getfiled expression doesn't allow the user to specify multiple select.

    I played around with several file select dialogs and found the one from Autodesk.Windows is actually quite good.

    I created a function to check the arguments of the lisp function and have a separate function to convert the string array output from the dialog into a result buffer of lispdatatype.text items.

    Like most of my lispmethod functions, I separate the .net function from the lispmethod function... that way the .net code could be used independently.



    Code:
    Imports Autodesk.AutoCAD
    Imports Autodesk.AutoCAD.Runtime
    Imports Autodesk.AutoCAD.EditorInput
    Imports Autodesk.AutoCAD.DatabaseServices
    Imports Autodesk.AutoCAD.ApplicationServices
    Imports Autodesk.AutoCAD.Windows
    Public Class FileSelectClass1
        
        ' LISP Function syntax:
        ' (FileSelect "Select Folder" "C:\\ACAD\\LISP\\" "" (+ 4 8 32 64 128 256 512 1024 2048))
        ' (FileSelect "Select Drawing" "C:\\ACAD\\LISP\\TEST2.DWG" "dwg" (+ 4 8 32 64 128 256 512 1024))
        ' (FileSelect "Select Drawings or JPG" "C:\\" "dwg;jpg" (+ 4 8 32 64 128 256 512 1024 4096))
    
        ''' <summary>
        ''' LISP Function for a file dialog box that can be set using flags to 
        ''' select folders, multiple files or files. See bit codes descriptions 
        ''' for flags below.
        ''' </summary>
        ''' <param name="rbfArguments"></param>
        ''' <returns>List of selected files or Folders</returns>
        <LispFunction("FileSelect")> _
        Public Function FileSelect(ByVal rbfArguments As ResultBuffer)
            Try
                Dim strReturn() As String
                If rbfArguments Is Nothing Then
                    strReturn = FileSelect()
                Else
                    Dim arrArguments As TypedValue() = rbfArguments.AsArray
                    strReturn = FileSelect(ArrayValue(arrArguments, 0), _
                                            ArrayValue(arrArguments, 1), _
                                            ArrayValue(arrArguments, 2), _
                                            ArrayValue(arrArguments, 3))
                End If
                If strReturn IsNot Nothing Then
    
                    Return StringArrayToResultBuffer(strReturn)
                End If
            Catch exception As Exception
                System.Diagnostics.Debug.Write(exception.ToString())
            End Try
            Return Nothing
        End Function
    
        ''' <summary>
        ''' .NET function to display a file select dialog box and return its value
        ''' </summary>
        ''' <param name="strTitle"></param>
        ''' <param name="strFileName"></param>
        ''' <param name="strFilter"></param>
        ''' <param name="intOpenDialogFlags"></param>
        ''' <returns> String array of selected item s</returns>
        Public Function FileSelect(Optional ByVal strTitle As String = "File Select Title", _
                                   Optional ByVal strFileName As String = "c:\\", _
                                   Optional ByVal strFilter As String = "dwg", _
                                   Optional ByVal intOpenDialogFlags As Int16 = 4
                                  )
            Try
                ' Flag Bit Codes
                ' .AllowAnyExtension = 4
                ' .SearchPath = 8
                ' .DefaultIsFolder = 16
                ' .DoNotTransferRemoteFiles = 64
                ' .NoUrls = 128
                ' .ForceDefaultFolder = 256
                ' .NoFtpSites = 512
                ' .NoShellExtensions = 1024
                ' .AllowFoldersOnly = 2048
                ' .AllowMultiple = 4096
    
                Dim openFileDialog As New  _
                    Autodesk.AutoCAD.Windows.OpenFileDialog(strTitle, strFileName, strFilter, "DialogName", _
                                                intOpenDialogFlags)
                With openFileDialog
                    If .ShowDialog() = System.Windows.Forms.DialogResult.OK Then
                        Return .GetFilenames
    
                    End If
                End With
            Catch ex As System.Exception
    
            End Try
            Return Nothing
        End Function
    
        ''' <summary>
        ''' Function to an get item in the array. 
        ''' </summary>
        ''' <param name="arrArguments"></param>
        ''' <param name="intItem"></param>
        ''' <returns> Item in array or Nothing for error </returns>
        Public Function ArrayValue(ByRef arrArguments As TypedValue(), ByVal intItem As Integer)
            If intItem < arrArguments.Length Then Return arrArguments(intItem).Value
            Return Nothing
        End Function
    
        ''' <summary>
        ''' Function to return a resultbuffer of typedvalue lispdatatype.text items
        ''' </summary>
        ''' <param name="strArguments"></param>
        ''' <returns>Result Buffer of text items </returns>
        Public Function StringArrayToResultBuffer(ByVal strArguments() As String)
            Try
                If strArguments IsNot Nothing Then
                    Dim rbfResult = New ResultBuffer(New TypedValue(LispDataType.ListBegin, -1))
                    For intItem = 0 To strArguments.Length - 1
                        rbfResult.Add(New TypedValue(LispDataType.Text, strArguments(intItem)))
                    Next intItem
                    rbfResult.Add(New TypedValue(LispDataType.ListEnd, -1))
                    Return rbfResult
                End If
            Catch exception As Exception
                System.Diagnostics.Debug.Write(exception.ToString())
            End Try
            Return Nothing
        End Function
    End Class
    Last edited by peter; 2014-02-18 at 04:33 PM.
    AutomateCAD

  2. #2
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,126
    Login to Give a bone
    1

    Default Re: File Multi Selection Dialog (and Folder Select)

    I have had trouble posting new threads for some reason, so I copied this thread and changed the title/revised posts so it could be posted.
    I asked Opie to look into the problem with posting threads.
    That is why the date appears wrong.
    AutomateCAD

Similar Threads

  1. Replies: 13
    Last Post: 2018-03-13, 12:52 AM
  2. Replies: 0
    Last Post: 2011-05-30, 07:07 AM
  3. multi select dialog box
    By rwbaker in forum VBA/COM Interop
    Replies: 3
    Last Post: 2006-03-10, 08:18 PM
  4. Open File Dialog Folder Addition
    By barathd in forum Revit Architecture - Tips & Tricks
    Replies: 0
    Last Post: 2005-02-07, 04:44 PM
  5. File selection dialog box
    By jgratton in forum CAD Management - General
    Replies: 5
    Last Post: 2005-01-20, 08:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •