I am trying to write a simple script that get input from a variable in ModelBuilder and use it in a Python script to "zoom" on a selected features in layout.

Here is the script and the error:

aprx = arcpy.mp.ArcGISProject('CURRENT')
mapx = aprx.listMaps()[0]
lyr = mapx.listLayers()[4]
quartier = arcpy.GetParameterAsText(0)

lyr.definitionQuery = '"NOM" = ' + "'"+GetParameterAsText(0)+"'"

lyt = aprx.listLayouts()[0]
mf = lyt.listElements('MAPFRAME_ELEMENT')[0]

mf.camera.setExtent(mf.getLayerExtent(lyr, False, True))

Traceback (most recent call last): File "C:\Users...\Projet\zoom.py", line 10, in lyr.definitionQuery = '"NOM" = ' + "'"+GetParameterAsText(0)+"'" NameError: name 'GetParameterAsText' is not defined

The model variable and Python variables have the exact same name.
The model variable data type is set as a string. The script variable datatype is set to all values.

My version of ArcGIS Pro is in French.

1 Answer 1


Where you have:

lyr.definitionQuery = '"NOM" = ' + "'"+GetParameterAsText(0)+"'"

it should be:

lyr.definitionQuery = '"NOM" = ' + "'"+arcpy.GetParameterAsText(0)+"'"

However, since you have previously set quartier = arcpy.GetParameterAsText(0) you could also use Python string formatting to do the same thing:

lyr.definitionQuery = "NOM = '{0}'".format(quartier)

Your Answer

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

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