5

I am using ArcGIS 10.2 and create a script tool in toolbox for attribute search on a layer, all the searching criteria is not compulsory, and user can combine multiple search criteria. But in the window all parameter together with (optional), I want to know whether there is a way to remove the (optional), the picture is attached.

enter image description here

  • 4
    No, the optional is added by the tool to show that the input parameter in the tool is optional=true. You could implement a custom C# / VB.net form and execute the tool from there but it wouldn't be from the toolbox. If you set the parameter to optional=false and set a default value, thence ignored the default value in the script it would remove it. – Michael Stimson Jun 13 '14 at 7:04
  • 1
    ..or use wxPython to build an own window :) – Alex Tereshenkov Jun 13 '14 at 7:13
3

The (optional) is added to the interface automatically when you specify that the parameter is optional so it really can't be avoided.

You can set all fields as required but default the values to something: Default Value

Then in the tool if the value is default or nonsensical (not found in file system for example):

import arcpy, os, sys

Oparam = sys.argv[1]
if os.path.exists(Oparam):
  # value found, assume it is a correct value
else:
  # value not found, assume it's skipped

Your best option for invalid values is arcpy.Exists which returns true if the data exists as an Esri type, files and folders can be checked using os.path.exists and either of os.path.isfile() and os.path.isdir() to validate if it is a file or directory respectively.

Otherwise you can create your own custom form in C# or VB.net and use the IGeoprocessor interface to run the tool. I don't recommend this as you can't list it with the tools in the toolbox.

1

Along the lines of what @michael said, just set all of the parameters to required, and in the tool validation script modify the updateParameters function to look like this:

def updateParameters(self):
  for i in range(6):
    if not self.params[i].value:
      self.params[i].value = '--'
  return

Then have your script to only use parameters that do not equal '--'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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