4Bart

get extent of selected features in layer - zoom to/locate script in mxd

Discussion created by 4Bart on Apr 2, 2014
Hi!

I need to make a script that does something like "zoom to/locate" = in ArcMap, user types a ID of an feature and map zooms to the feature... It needs to be independent on data in current mxd.

My idea is to do it like this:
import arcpy
dtb="Database Connections\mygdtb.sde"
arcpy.env.workspace=dtb
searchedLayer="MYGDTB.DATAOWNER.searchedLayer"
searchedValue=arcpy.GetParameterAsText(0)
sql="[searchedField]='"+searchedValue+"'"
lyr=arcpy.MakeFeatureLayer_management(searchedLayer, "lyr")
selectedItem=arcpy.SelectLayerByAttribute_management(lyr,"NEW_SELECTION",sql)

and than use layer´s method getSelectedExtent, than pass that extent to current mxd and zoom it to that extent...

But it doesn´t work that way - I´m not able to get extent of selected features.... How to do it? Any ideas?

I would appreciate any help... Thank you!

Outcomes