I am trying to get an user input for getting a parcel name and pan the map to that selection. What am I doing wrong in the code below?

import arcpy

#Msg box to get parcel Name
parcel_Name = str(arcpy.GetParameterAsText(0))
arcpy.AddMessage ("Loading parcel " + parcel_Name)


    mxd = arcpy.mapping.MapDocument('CURRENT')
    df = arcpy.mapping.ListDataFrames(mxd, "Layers") [0]
    ssparcel = arcpy.mapping.ListLayers(mapDoc, "ssparcel", df)[0]

    whereClause = "Name ='%s'" % parcel_Name
    arcpy.SelectLayerByAttribute_management(ssparcel, "NEW_SELECTION", whereClause)
    df.extent = df.panToExtent(ssparcel.getSelectedExtent())
        #df.scale *= 1.5


    arcpy.AddWarning ("Error")


Removed the "try" and got the following error:

Executing: Script "0002" Start Time: Thu Jun 05 11:32:14 2014 Running script Script... IndentationError: unexpected indent (abcd.py, line 9) Failed to execute (Script). Failed at Thu Jun 05 11:32:14 2014 (Elapsed Time: 0.00 seconds)

  • Can you pull the code out of the try/except block so you can get the actual error being raised and add it to your question? Jun 5, 2014 at 18:09
  • The Indentation Error is occurring if you removed the Try but did not remove the indentations. Python needs all of the code properly indented to work.
    – Dan
    Jun 5, 2014 at 18:50

1 Answer 1


The following worked for me in the Python window:

mxd = arcpy.mapping.MapDocument("current")
df = arcpy.mapping.ListDataFrames(mxd)[0]
lyr = arcpy.mapping.ListLayers(mxd, "Prog*", df)[0]
arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", "OBJECTID=1")

Or, the last two lines can be combined as (like you did):

df.extent = df.panToExtent(lyr.getSelectedExtent())

EDIT: The difference I see with yours is the variable mapDoc.

How do I pass a string parameter obtained from user like "OBJECTID="&userinput?


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.