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