1

I have a map automation script that I have been using in ArcMap 10.5 with Python 2.7. I just learned the in's and out's of ArcGIS for Pro and would like to migrate my processing to Pro. It's taking a while to migrate the Python 2.7 code into something that will take in the Python 3 module of Pro, but I think for the most part, I've been able to translate my code.

With the exception of a couple of arcpy functions, so I wanted to see if anyone had any insight into how to do something. In my code, after selecting certain features, I have the code (2.7) use:

df.zoomToSelectedFeatures()

When I try to run this in Pro, it doesn't like it. It appears that "zoomToSelectedFeatures" is no longer supported in Python 3? Does anyone know a workaround to move the map automatically to the selected features in an automation script?

closed as off-topic by PolyGeo Jan 4 '18 at 13:27

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

3

you can use the Analyze Tools for PRO tool. input your 2.7 py script and the result will be a .txt file highlighitng what needs to be changed (and telling you what to change it to) see here: http://desktop.arcgis.com/en/arcmap/10.3/tools/data-management-toolbox/analyzetoolsforpro.htm

for df.zoomtoselectedfeatures is now replaced with the following:

zoomToAllLayers ({selection_only}, {symbolized_extent}) 

Modifies the MapFrame view to match the extent of all layers or selected layers in a map.

http://pro.arcgis.com/en/pro-app/arcpy/mapping/mapframe-class.htm

enter image description here

This is the ESRI Sample Code Snippet. enter image description here

you need to replace zoomToBookmark with zoomToAllLayers(selection_only)

  • I used the Analyze Tools for Pro tool and all it told me was that I was missing parentheses in my print functions; it didn't tell me about all of the other items I had to correct through error checking in the Python window. – Dave Dec 12 '17 at 20:22
  • I edited my answer – NULL.Dude Dec 12 '17 at 20:24
  • did the following fix your issue? I tested on my end and it worked. – NULL.Dude Dec 13 '17 at 12:50
  • I'm trying to work it in, but it's not identifying that function. It fails and tells me that 'Map' or 'ArcGISProject' object has no attribute 'zoomToAllLayers' – Dave Dec 14 '17 at 13:26
  • you need to understand there is no more arcpy.mapping its now arcpy.mp. read it form here pro.arcgis.com/en/pro-app/arcpy/mapping/… – NULL.Dude Dec 14 '17 at 13:27

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