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

569
0
04-02-2014 05:41 AM
J_B__K_
New Contributor III
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!
Tags (2)
0 Kudos
0 Replies