import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers") [0]
df.zoomToSelectedFeatures()
arcpy.RefreshActiveView()
Solved! Go to Solution.
A lot of things have changed when moving to pro, most noticeable is the mapping module being renamed to mp. In addition, any map document will now be drilled down through the project and the individual layouts within those projects.
What I was able to do is the following but it needs to be completed through the layout then map object:
import arcpy aprx = arcpy.mp.ArcGISProject("CURRENT") layout1 = aprx.listLayouts('Layout')[0] map1 = layout1.listElements('MAPFRAME_ELEMENT')[0] map1.zoomToAllLayers(True)
Not sure on refreshing the dataframe but that should be a good place to start.
I hope this helps!
Did you get an error message?
The only pure python statement there is the "import arcpy" line, everything else is related to arcmap. If it can't find arcpy, then there is an installation problem of python (which shouldn't be an issue unless you have old versions of python around and you haven't cleaned up your python paths).
Dan, thanks for your response. I used the analysis tool in pro and I am attaching the result. The python code is part of a model I am running successfully in arcmap 10.2. I am executing the . mxd in pro and it gives me an error in the script portion. Everything else in the model works. I installed pro on the same machine as 10.2 and I did not check where 3.4 is installed. I see where 2.7 is installed.
A lot of things have changed when moving to pro, most noticeable is the mapping module being renamed to mp. In addition, any map document will now be drilled down through the project and the individual layouts within those projects.
What I was able to do is the following but it needs to be completed through the layout then map object:
import arcpy aprx = arcpy.mp.ArcGISProject("CURRENT") layout1 = aprx.listLayouts('Layout')[0] map1 = layout1.listElements('MAPFRAME_ELEMENT')[0] map1.zoomToAllLayers(True)
Not sure on refreshing the dataframe but that should be a good place to start.
I hope this helps!
In addition to what Alexander Nohe mentioned, here is a link to the documentation:
Introduction to arcpy.mp—ArcPy | ArcGIS for Professionals
and this one is relevant too:
Migrating arcpy.mapping to ArcGIS Pro—ArcPy | ArcGIS for Professionals
i just love that projects are called *.aprx .... and the new python toolboxes are like a return to the dialog designer... this is great
Thanks to y’all for your help.
Was your question replied? In that case you should mark the post that answer your question as "Correct Answer". Personally I believe the post by Alexander Nohe answered your question.
Xander - I agree. I went ahead and marked it correct.