1

I'm setting up a Script Tool (Arc 10.2.2) where the first parameter will be a CSV file chosen by the user, always from the same folder.

When the user clicks the first parameter's windows navigator drop down (to select the desired .csv) I want the ensuing catalog window to begin at the folder I specify.

I've already tried setting the folder path in the "Default" field of the Parameter Properties Window but that didn't work. This made the path appear in the Parameter field, but when the drop down is clicked that path is ignored and the user is shown an entirely different location.

I'm quite sure the proper validation code will achieve my desired functionality, I just don't know what that is. I have read many ESRI web pages on the topic but have yet to find the proper coding.

How do you force a Tool Parameter Input Field to Begin at a Specific Folder?

I seek the proper function and which module it should be in (i.e. which of the standard 3 validation modules: _init_(self) , initializeParameters(self) , or updateParameters(self).).

3
  • Sounds like you may need to use Tool Validation.
    – PolyGeo
    May 10, 2018 at 22:28
  • 1
    @PolyGeo - I've been researching validation scripts but still have not been able to find the solution to my problem. Thus, I have reactivated my question. Thank you.
    – Waterman
    May 14, 2018 at 22:17
  • I think your question distils to being "Can ArcPy control workspace that Catalog browser opens in?" I don't have time to investigate that at the moment but I suspect that it cannot. Your last edit clarified that "I want the ensuing catalog window to begin at the folder I specify". If you drop the requirement for the Catalog browser to be involved then I think using ListFiles in initializeParameters(self) will do what you need. For ArcPy questions please always include a code snippet that shows what you have tried.
    – PolyGeo
    May 14, 2018 at 22:39

1 Answer 1

2

Since the user will always select a file from the same folder, then you don't need to have the file browser involved. This solution won't set a default directory; instead, it will populate a drop-down list of all the csv files that are within your desired directory.

In the tool's properties, instead of setting the parameter type to File, set it to String.

Then, in the validation code:

def initializeParameters(self):
    dir_f = r'path\to\csv\directory'
    fs = [os.path.join(dir_f, f) for f in os.listdir(dir_f) if f.endswith('.csv')]
    self.params[0].filter.list = fs
    return

Alternatively, you could display just the file names rather than their full paths, but when the tool executes, you would need to be sure to prepend the directory path.

1
  • Beautiful. Achieves exactly what I need. Much appreciated!
    – Waterman
    May 16, 2018 at 20:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.