Script tool dependency - using a conditional?

226
1
Jump to solution
11-10-2020 05:07 AM
CraigMacDonell
New Contributor

Trying to make a script tool for a repetitive data conversion task I perform regularly. Have two "Processing Methods". The first, "Individual", takes each input file (from the Input Directory - folder) and produces an equivalent, converted output file. The second, shown below as "Combine" takes the same inputs, but combines them into one combined output file.

"Individual" is the default, and I have got that working perfectly. If this "Individual" option is used, the input filename is extracted to form the output filename. 

But if someone uses the combined option, then you have many input filenames which are likely (but not always) going to have some sequence. Therefore I want to give the user the opportunity to provide a filename for the single output file. I, however, need this option to be blank/uneditable when the "Individual" method is selected. 

I have had a bit of a play around, and searched the web. Have also tried looking for existing tools that have this functionality so that I may be able to compare and replicate. 

0 Kudos
1 Solution

Accepted Solutions
RandyBurton
MVP Regular Contributor

I suggest the ToolValidator for this.  Modifying the example given in the enable/disable a parameter section, the code would look something like:

 

def updateParameters(self):
    # params[0] = Individual or Combine
    # params[4] = Output Filename
    if self.params[0].value == "Combine":
        self.params[4].enabled = True
    else:
        self.params[4].enabled = False

 

 

View solution in original post

1 Reply
RandyBurton
MVP Regular Contributor

I suggest the ToolValidator for this.  Modifying the example given in the enable/disable a parameter section, the code would look something like:

 

def updateParameters(self):
    # params[0] = Individual or Combine
    # params[4] = Output Filename
    if self.params[0].value == "Combine":
        self.params[4].enabled = True
    else:
        self.params[4].enabled = False

 

 

View solution in original post