Saturday, 10 September 2016

arcpy - Deriving input based on other parameters in Python script tool?


I have a folder and it contains two feature classes, e.g., a.shp and b.shp. The script tool created has two parameters. The first one is the model location, and the second one needs a feature class (a.shp), as shown in the below picture. enter image description here What I really want is every time when I set up the model location for the first input, the second input will automatically find the a.shp as the input rather than the user needs to choose a.shp from that folder. I noticed that the dependency is probably what I really need, but there is no code example. Any suggestions?


I am using ArcGIS 10.3.1 Advanced License.



Answer



You want to look into Script Tool Validation - see Understanding validation in script tools and Customizing script tool behavior with Validation


Validation allows you to pass some arcpy code when your tool dialog is open, and have those results update/enable/disable/etc. the parameters in your tool dialog before you hit OK to run the tool.


As part of this you can do an if/else where it can check the value in field one, then populate the value in field two based on field one. If you wanted, you could also have dynamic drop-downs where the entire drop-down for field 2 changes based on your value in field one.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...