What do I need to modify in the following python script in 2.7 to convert it to 3.4 used in professional:

4790
8
Jump to solution
12-16-2014 08:40 AM
angelkosfiszer
New Contributor

import arcpy

mxd = arcpy.mapping.MapDocument("CURRENT")

df = arcpy.mapping.ListDataFrames(mxd, "Layers") [0]

df.zoomToSelectedFeatures()

arcpy.RefreshActiveView()

0 Kudos
1 Solution

Accepted Solutions
AlexanderNohe1
Occasional Contributor III

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!

View solution in original post

8 Replies
DanPatterson_Retired
MVP Emeritus

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).

0 Kudos
angelkosfiszer
New Contributor

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.

0 Kudos
AlexanderNohe1
Occasional Contributor III

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!

XanderBakker
Esri Esteemed Contributor

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

DanPatterson_Retired
MVP Emeritus

i just love that projects are called *.aprx .... and the new python toolboxes are like a return to the dialog designer... this is great

0 Kudos
angelkosfiszer
New Contributor

Thanks to y’all for your help.

0 Kudos
XanderBakker
Esri Esteemed Contributor

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.

0 Kudos
curtvprice
MVP Esteemed Contributor

Xander - I agree. I went ahead and marked it correct.

0 Kudos