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
Solved! Go to Solution.
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.
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.
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
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.
here what i did by it did not work
I believe that my code is wrong. Thanks to give me some ideas to correct it
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.
Thanks a lot
it works perfectly
As I mention before, It works perfectly.
How I can program to run the updateParameter (self) if any paramerter is changed?
Thanks
UpdateParameter already runs every time a parameter is changed.