Select to view content in your preferred language

remove value from a list with ToolValidator

1005
6
Jump to solution
07-17-2012 03:23 AM
KarstenRank
Frequent Contributor
Hi,

I'm trying to import the values from a table in two different parameters.  Parameter 1 is is a single choice field, parameter 2 is a multi choice field. It is important, that the choosen value of parameter 1 should not be selectable for parameter 2.
How can I write this in the ToolValidator with python?

Best,
Karsten
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor
The Tool Validator will successfully convert the field names to strings.  Try the following:

1.  Set the data type for the Dimensions-Felder parameter to 'String'
2.  Update the Tool Validator with the following code:

  def updateParameters(self):     if self.params[0].value:       list = []       lstFields = arcpy.ListFields(str(self.params[0].value))       for field in lstFields:         list.append(field.name)       list.remove(str(self.params[1].value))       self.params[2].filter.list = list     return

View solution in original post

0 Kudos
6 Replies
JakeSkinner
Esri Esteemed Contributor
Hi Karsten,

Here is an example on how you can do this by updating the updateParameters function:

def updateParameters(self):
    if self.params[0].value:
      list = []
      mxd = arcpy.mapping.MapDocument("CURRENT")
      df = arcpy.mapping.ListDataFrames(mxd)[0]
      for layer in arcpy.mapping.ListLayers(mxd, "", df):
        list.append(layer.name)
      list.remove(str(self.params[0].value))
      stringFilter = self.params[1].filter
      stringFilter.list = list
    return


For the multivalue parameter, you will want to set the Data Type to 'String' within the Parameters tab.
0 Kudos
KarstenRank
Frequent Contributor
Thanks for your answer!

I still have the problem, that the list I want to remove something comes from the same table I open. I have made screenshot to show it. [ATTACH=CONFIG]16185[/ATTACH]

The value choosen in "Listen-Feld" should not be shown in the "Dimensions-Felder", althoug it is part of the table I take as source.

Best Karsten
0 Kudos
JakeSkinner
Esri Esteemed Contributor
Can you attach a screen shot of your Tool Validator tab, and a screen shot of your Parameters tab?  Also, are you working with Tables or Feature Classes?
0 Kudos
KarstenRank
Frequent Contributor
To show you what I want, I set both parameter as Fields.[ATTACH=CONFIG]16186[/ATTACH]

My ValidatorTool code is still empty. I work with tables, because I want to create a feature class after my script is finished.

If I take string for the "Dimesions-Felder", how can I create the string form the fields in the table?
0 Kudos
JakeSkinner
Esri Esteemed Contributor
The Tool Validator will successfully convert the field names to strings.  Try the following:

1.  Set the data type for the Dimensions-Felder parameter to 'String'
2.  Update the Tool Validator with the following code:

  def updateParameters(self):     if self.params[0].value:       list = []       lstFields = arcpy.ListFields(str(self.params[0].value))       for field in lstFields:         list.append(field.name)       list.remove(str(self.params[1].value))       self.params[2].filter.list = list     return
0 Kudos
KarstenRank
Frequent Contributor
Thanks Jake!!

This is what I searched so long!!!!

Greetings from Bavaria!

Karsten
0 Kudos