I selected data by using select layer by attribute, then I need to only select these selection and zoom in to the selection. my code is this, it can zoom in base on the scale I set, but I see other adjacent polygon that has other Code_No, why?

Layer = arcpy.mapping.ListLayers(mxd, "lyr", df)       
arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", "Code_NO = '%s'"%mycodeNo)           
df.extent = lyrLayer1.getSelectedExtent()
df.scale *= 2

If your layer is called "lyr" and you have already created your map document (mxd) and data frame (df) objects, then the following should have a better chance of working. I am not sure about your SQL expression so have hardcoded a value. For your initial testing use something you know exists and then work on the SQL expression after that.

lyrLayer1 = arcpy.mapping.ListLayers(mxd, "lyr", df)[0]     
lyrLayer1.definitionQuery = ''' "Code_NO" = 'TEST_VALUE' '''
df.extent = lyrLayer1.getSelectedExtent()
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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