Creating a File parameter for a GP tool

443
2
02-17-2022 03:40 PM
BerndtNording
Occasional Contributor

I created some ArcObjects code that creates a geoprocessing tool that creates a featureclass from some input files. The code creates a GP tool that works as it should, except for one problem: the GP parameter for the input files accepts all files when it is supposed to only accept files with the extension .jxl or .xls.

There is no documentation on how to do this, but below is the code snippet of what I wrote to create the input file parameter.  I've also converted the tool to a Python tool (which has much better documentation) and it does filter input files to just the allowed ones. I assume the underlying objects are the same for the .Net SDK as for ArcPy, so there should be a way to get the .net authored tool to work as well. I also looked for clues in the Pro SDK, but came up with nothing since Pro doesn't even support creating GP tools with .net.

        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        parameter = New GPParameterClass()
        Dim inputType As IGPDataType = New DEFileTypeClass()

        Dim pGXFileFilter As IGxFileFilter = New GxFileFilterClass
        pGXFileFilter.AddFileType("jxl", "Trimble JXL Files", "")
        pGXFileFilter = New GxFileFilterClass
        pGXFileFilter.AddFileType("xls", "Excel Files", "")
        Dim pGXFilterInfo As IGxFilterInfo
        pGXFilterInfo = CType(inputType, IGxFilterInfo)
        pGXFilterInfo.OpenGxObjectFilters.Add(pGXFileFilter)
        pGXFilterInfo.SaveGxObjectFilters.Add(pGXFileFilter)

        Dim mvType As IGPMultiValueType = New GPMultiValueTypeClass()
        mvType.MemberDataType = inputType
        Dim mvValue As IGPMultiValue = New GPMultiValueClass()
        mvValue.MemberDataType = inputType

        parameter.Name = "input_files"
        parameter.DisplayName = "Input Files"
        parameter.ParameterType = esriGPParameterType.esriGPParameterTypeRequired

        parameter.Direction = esriGPParameterDirection.esriGPParameterDirectionInput
        parameter.DataType = CType(mvType, IGPDataType)
        parameter.Value = CType(mvValue, IGPValue)
        pParameters.Add(parameter)

        ' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
0 Kudos
2 Replies
DuncanHornby
MVP Notable Contributor

I can see one problem with your code and that is you create pGXFileFilter and set it to file type "jxl" then you overwrite the same object setting the file type to "xls".

0 Kudos
BerndtNording
Occasional Contributor

Yes, you are right! But that error should still restrict the file types to just .xls. After correcting that error, the tool still allows any type of file.

 

0 Kudos