Select to view content in your preferred language

zoomToSelectedExtent or dataDrivenPages.refresh()

1673
6
12-17-2012 01:25 PM
ChadFoster
Deactivated User
pre 10.1, I had a script that would zoom to selected features.  at 10.1 that same script crashed when it came to zoomToSelectedFeatures().  Is this something that is going to become usable again?  If not, is there a workaround? 

The script uses a MXD that has Data Driven Pages enabled, I have also been trying to get dataDrivenPages.refresh() to work, but I keep getting errors. 

Has anyone experienced either of these situations?

Thanks
Tags (2)
0 Kudos
6 Replies
JeffBarrette
Esri Regular Contributor
DF.zoomToSelected() works fine at 10.1.  There must be something specific to your code.  The same applies to .refresh().  It would be much more helpful if you provided a snippet of your code along with the error messages.

Jeff
0 Kudos
ChadFoster
Deactivated User
In  nutshell, the script is used in an MXD with Data Driven Pages.  I can see the progression of the script on screen while running.  The select statement below is working, but the zoomToSelectedFeatures() does not work and there is no error message.

At the end of the script when I try the data driven pages refresh, I encounter this error message:
Traceback (most recent call last):
  File "T:\1_DOUGLAS_PROJECTS\B_RESEARCH_AND_DEVELOPMENT\3_PROGRAMMING_AND_SCRIPTING\PYTHON\DC_NOTICING_SINGLE.py", line 198, in <module>
    mxd.dataDrivenPages.refresh()
  File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_
    return fn(*args, **kw)
  File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\_mapping.py", line 330, in refresh
    return convertArcObjectToPythonObject(self._arc_object.refresh(*gp_fixargs((args), True)))
ValueError: PageLayoutObject: Error in refreshing RefreshDataDrivenPages


mxd = arcpy.mapping.MapDocument (r"T:\1_DOUGLAS_PROJECTS\A_CLIENT_PROJECTS_ARC\1_INTERNAL_CLIENTS\A_GENERAL_FUND\2_PLANNING_CDEV\C_NOTICING\MXD\ARCGIS10_DC_NOTICING_SINGLE_PARCEL.mxd")
df = arcpy.mapping.ListDataFrames (mxd, "Layers")[0]
arcpy.SelectLayerByAttribute_management(layer, "NEW_SELECTION", selstring)
df.zoomToSelectedFeatures()
mxd.dataDrivenPages.refresh()


The "layer" in the select statement is from arc.getParameterAsText(0) with data type in properties parameters set to Layer.
0 Kudos
JeffBarrette
Esri Regular Contributor
The "layer" in the select statement is from arc.getParameterAsText(0) with data type in properties parameters set to Layer.


Try this:
Set the layer name parameter as a string type.  Enter a string value that is equal to the layer name in the TOC.

Then try:
lyrName = arcpy.getParameterAsText(0)
mxd = arcpy.mapping.MapDocument (r"T:\1_DOUGLAS_PROJECTS\......\_SINGLE_PARCEL.mxd")
df = arcpy.mapping.ListDataFrames (mxd, "Layers")[0]
lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", selstring)


Jeff
0 Kudos
ChadFoster
Deactivated User
Jeff,

I made the corrections as you suggested, the script still functions, however the
df.zoomToSelectedFeatures()
does not do anything and the
mxd.dataDrivenPages.refresh()
still throws an error message. 

Traceback (most recent call last):
  File "T:\1_DOUGLAS_PROJECTS\B_RESEARCH_AND_DEVELOPMENT\3_PROGRAMMING_AND_SCRIPTING\PYTHON\DC_NOTICING_SINGLE.py", line 200, in <module>
    mxd.dataDrivenPages.refresh()
  File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_
    return fn(*args, **kw)
  File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\_mapping.py", line 330, in refresh
    return convertArcObjectToPythonObject(self._arc_object.refresh(*gp_fixargs((args), True)))
ValueError: PageLayoutObject: Error in refreshing RefreshDataDrivenPages

Failed to execute (SINGLEPARCELNOTICING).
0 Kudos
JeffBarrette
Esri Regular Contributor
Can you send a map package and your script to jbarrette@esri.com.  I'll take a look.

If you can't send me a map package, at least send my your script so I can look at it.

Jeff
0 Kudos
DanDeegan
Regular Contributor

Hi Chad. I was going through this exact script and wanted to have it refresh data driven pages. Coincidentally, I stumbled on this post.

This worked:

ddp = mxd.dataDrivenPages #creates the object
ddp.refrech()‍‍

(he worked where I work now and I am updating his script)

0 Kudos