Select to view content in your preferred language

How to customize parameters of a AcrToolBox?

3728
8
Jump to solution
04-15-2015 06:24 AM
SaidAkif
New Contributor III

Hi all,

Here  is my problem. I want to create an AcrToolbox to make a batch of delete (example). I can perform this delete on a single feature class or several one contained in a workspace. so there is four parameters of this arctoolbox:

1- Boolean parameter: Process a single feature class or several

2- Workspace parameter

3- Feature class parameter

4- Field parameter

What I want is that when the boolean is checked (several feature class to process), a function run automatically to take the table fields of the firs feature class in the workspace and show them in Field parameter. When the boolean is unchecked (single feature class), the function retrieve the field of this feature class and put them in Field parameter.

Usualy, It is quite easy to do it when only a single feature class is used. I just set Obtained from in Parameter Properties.

Thanks

0 Kudos
1 Solution

Accepted Solutions
FreddieGibson
Regular Contributor II

I believe that the image below shows what you're trying to do. You should also note that your last parameter should be of type field instead of string. You don't need to use the validator to populate the fields. You would only need to use the options available in the user interface for a field type parameter. I believe you'd just need to set the Obtained_From parameter.

ToolValidator.png

View solution in original post

0 Kudos
8 Replies
FreddieGibson
Regular Contributor II

I'm assuming that your tool is designed to a particular field if its found with a feature class. What you'll need to accomplish this is a tool validator class within a script tool.

Customizing Script Tool Behavior

http://resources.arcgis.com/en/help/main/10.2/index.html#//00150000000t000000

You could setup your tool as follows:

1. Feature Class (Required)

2. Field (Required): Obtained from parameter 1

3. Task (String with ValueList filter : Default value is SINGLE) : This parameter will determine if you only delete the field from the chosen feature class or if you search for features within the workspace.

4. Workspace (Optional and disabled) : Implement validation logic where if the first parameter value is assigned we assign its workspace to this parameter. Users will not be allowed to manipulate this. They essentially set the workspace by selecting a feature class within it. That way can ensure it contains the field they need to search for.

If needed, parameter 1 and 4 can be assigned as multivalue and you can zip up the values between the two so that you can remove particular fields from each workspace.

0 Kudos
SaidAkif
New Contributor III

Thanks a lot

Can you please tell me ho to retreive the first feature class in the workspace. I believe that I have to do that in Validation/def updateParameters(self)

Thanks

0 Kudos
FreddieGibson
Regular Contributor II

Within the UpdateParameters parameter of the validator you would need to check if the workspace parameter has a value and if the feature class parameter hasn't been validated. Once you confirm this you could use arcpy.ListFeatureClasses to list the feature classes within the workspace or use arcpy.da.Walk. You would return the set the value returned by these functions as the value for the feature class parameter.

0 Kudos
SaidAkif
New Contributor III

here what i did by it did not workCapture4.PNG
I believe that my code is wrong. Thanks to give me some ideas to correct it

0 Kudos
FreddieGibson
Regular Contributor II

I believe that the image below shows what you're trying to do. You should also note that your last parameter should be of type field instead of string. You don't need to use the validator to populate the fields. You would only need to use the options available in the user interface for a field type parameter. I believe you'd just need to set the Obtained_From parameter.

ToolValidator.png

0 Kudos
SaidAkif
New Contributor III

Thanks a lot

it works perfectly

0 Kudos
SaidAkif
New Contributor III

As I mention before, It works perfectly.

How I can program to run the updateParameter (self) if any paramerter is changed?

Thanks

0 Kudos
FreddieGibson
Regular Contributor II

UpdateParameter already runs every time a parameter is changed.

0 Kudos