1

I created a script. I would like the user to be able to select a value from the drop-down list. Once the value is selected, I would like this value to be displayed on my cover page that I created. However, when I execute the code, instead of a single value that is displayed, all the values in the drop-down list are displayed as the title of the cover page. Here is so attached my code and the result that the performance produces.

class ToolValidator:
 # Class to add custom behavior and properties to the tool and tool parameters.
 def __init__(self):
 # set self.params for use in other function
 import arcpy, os
 
 self.params = arcpy.GetParameterInfo()
 
 def initializeParameters(self):
 # Customize parameter properties. 
 # This gets called when the tool is opened. 
 return
 
 
 def updateParameters(self):
 # Modify parameter values and properties.
 # This gets called each time a parameter is modified, before 
 # standard validation.
 aprx = arcpy.mp.ArcGISProject("CURRENT") 
 map1 = aprx.listMaps("Map1")[0]
 cov = aprx.listLayouts("Mapbook_global")[0]
 lyr_planches = map1.listLayers("assemblage_carro_11000_5000")[0]
 ## titre 
 TheRows = arcpy.SearchCursor(lyr_planches) 
 liste = []
 for TheRow in TheRows: 
 liste.append(TheRow.cis) 
 TheName = list(set(liste)) 
 title = TheName
 titleTxt =cov.listElements("TEXT_ELEMENT","title")[0]
 titleTxt.text = title
 
 self.params[0].value = lyr_planches
 self.params[1].filter.list = TheName
 
 return
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked May 30, 2022 at 14:39
1
  • The first rule of ArcPy cursors is "Don't use arcpy.SearchCursor" (Use arcpy.da.SearchCursor instead). Python best practice is to use lower_case variable names and UpperCase class names. Your code goes out of its way to make a list then a set the a list again, and calls that (eventually) title, so it shouldn't be a surprise that all the values are present. You haven't included the code where the value is used. Commented May 30, 2022 at 15:25

1 Answer 1

1

You're setting the titleTxt to title which is a list which make all the values in the drop-down list to be displayed

TheName = list(set(liste)) 
title = TheName

Instead, move that part to the main script body

def execute(self, parameters, messages):
 title = parameters[1].valueAsText
 
 aprx = arcpy.mp.ArcGISProject("CURRENT") 
 map1 = aprx.listMaps("Map1")[0]
 cov = aprx.listLayouts("Mapbook_global")[0]
 
 titleTxt =cov.listElements("TEXT_ELEMENT","title")[0]
 titleTxt.text = title
answered May 30, 2022 at 22:34
2
  • Merci pour votre retour. J'ai repris et ça marche. Commented Jun 8, 2022 at 13:47
  • If it works, mark it as the correct answer. Commented Jun 8, 2022 at 18:51

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.