Select to view content in your preferred language

Create output folder navigation option in python tool

1836
6
Jump to solution
07-27-2022 05:40 AM
WadeWall
Regular Contributor

Hi all,

I have been creating python tools within a python toolbox in Arcgis Pro 2.8, but can't figure out how to add a folder navigation icon so that, when the user selects the output the location, they can navigate there.

Thanks for any information.

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

Looking at the 2 tools we mentioned, Create Feature Class and Copy, they have different geoprocessing data types for their input/output.

Create Feature Class uses Workspace;Feature Dataset and String (the same as my solution).

Copy uses the Data Element type for both input and output.

Maybe if you used that type for your Parameter it would give the desired behavior?

Something like:

def getParameterInfo():
    input_directory = Parameter(
        displayName = 'Input Data',
        name = 'input_data',
        datatype = 'DEType',
        parameterType = 'Required',
        direction = 'Input')

    input_directory = Parameter(
        displayName = 'Output Data',
        name = 'output_data',
        datatype = 'DEType',
        parameterType = 'Required',
        direction = 'Input')

    return [input_data, output_data]

 

Curious to know if this works.

Also curious why ESRI has the actual tools structured in different ways. The "Copy" tool cannot copy between different workspaces e.g. Folder -> GDB.

View solution in original post

0 Kudos
6 Replies
by Anonymous User
Not applicable

Here's a simple getParameterInfo() method for one of my tools that accepts a directory path as input. The "folder navigation icon" appears in the Arc Pro GUI when the tool is opened.

The docs for Parameter definition and data types.

 

def getParameterInfo():
    input_directory = Parameter(
        displayName = 'Input Project Folder',
        name = 'input_directory',
        datatype = 'DEWorkspace',
        parameterType = 'Required',
        direction = 'Input')

    input_directory.filter.list = ['File System']

    return [input_directory]

 

WadeWall
Regular Contributor

Thanks for the reply. I actually have that working on the input side. What I want to do is be able to browse to an outfolder and type a new output name. We can do this using some of the native ArcGIS tools, I just can't figure out how to do it with a python toolbox. Here is an example:

outfile = arcpy.Parameter(
            displayName="outfile",
            name="outFile",
            datatype="GPString",
            parameterType="Required",
            direction="Output")

 

It may be that I am using "GPString" and so I have to hard code the path. I am just not sure.

by Anonymous User
Not applicable

Alright I think I understand what you're trying for.

Interesting question - I would handle this by having 2 inputs like in the Create Feature Class tool. One field to select output directory/workspace. One field of free text to define the output name. And then handle the validation and pathing etc in code.

 

But that's not a direct solution to what you're asking. Can you post an example ESRI tool which has the desired behavior? Now I'm curious about this too 🙂

I think the "derived outputs" section of the docs is the right direction? The docs aren't clear to me how that's used though...

0 Kudos
WadeWall
Regular Contributor

You are right. I could do them as one parameter to navigate to the folder and one to provide a new name. It is just easier to do it in one parameter. For example, the copy geoprocessing function allows you to select a folder and a new name for the copied feature.

0 Kudos
by Anonymous User
Not applicable

Looking at the 2 tools we mentioned, Create Feature Class and Copy, they have different geoprocessing data types for their input/output.

Create Feature Class uses Workspace;Feature Dataset and String (the same as my solution).

Copy uses the Data Element type for both input and output.

Maybe if you used that type for your Parameter it would give the desired behavior?

Something like:

def getParameterInfo():
    input_directory = Parameter(
        displayName = 'Input Data',
        name = 'input_data',
        datatype = 'DEType',
        parameterType = 'Required',
        direction = 'Input')

    input_directory = Parameter(
        displayName = 'Output Data',
        name = 'output_data',
        datatype = 'DEType',
        parameterType = 'Required',
        direction = 'Input')

    return [input_data, output_data]

 

Curious to know if this works.

Also curious why ESRI has the actual tools structured in different ways. The "Copy" tool cannot copy between different workspaces e.g. Folder -> GDB.

0 Kudos
WadeWall
Regular Contributor

Thanks again. 'DEType' was exactly what I was looking for and worked perfectly.

0 Kudos