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
1 Answer 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
-
Merci pour votre retour. J'ai repris et ça marche.Raphael05– Raphael052022年06月08日 13:47:03 +00:00Commented Jun 8, 2022 at 13:47
-
If it works, mark it as the correct answer.Ahmad Raji– Ahmad Raji2022年06月08日 18:51:31 +00:00Commented Jun 8, 2022 at 18:51
arcpy.SearchCursor
" (Usearcpy.da.SearchCursor
instead). Python best practice is to uselower_case
variable names andUpperCase
class names. Your code goes out of its way to make alist
then aset
the alist
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.