Is it possible to drive one mxd (pan) using a different mxd with python?

2980
3
09-09-2014 03:15 AM
DanielHall_Ballester
New Contributor III

I have 2 mxd's.

mxdA and mxdB

They both show different data, but are both in the same coordinate system.

I want to be able to sync mxdB with mxdA, so that if I pan / zoom in mxdA, I can then, with a single button press, view the same extent in mxdB.

I know that this is possible using a Viewer window (where a 2nd data frame is used rather than a 2nd mxd), however there is a memory leak present where a Viewer window is used alongside an editing session with snapping turned on (NIM103256) which causes our session to crash after <1 hour of editing.

I know that another option could be to use production mapping views, but these seem to be limited to both mxd's having the same datasets, and once you have opened mxdB and linked it to a view, you are then unable to update the view file using mxdA because it is locked by mxdB. This is not practical for us as it would mean closing and re-opening mxdB many times every day (50+)

I'm hoping that there is a way using python where I can calculate the center point of the active dataframe in mxdA and then pan/zoom mxdB (which is already open) to the same location. I can then create a button as an ESRI Add-in to do this automatically.

Calculating the center point is simple enough

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

# Calculate the centre X coordinate
x = (df.extent.XMax + df.extent.XMin)/2
#Calculate the centre Y coordinate
y = (df.extent.YMax + df.extent.YMin)/2

But I'm struggling with passing this center point information to mxdB to get it to pan. Is this even possible without using ArcObjects?

EDIT:

I have written some code that can be run in mxdB which will update mxdB based on the extent of mxdA. However, I need to be able to run the code in mxdA and for it to update the extent of mxdB (as mxdB is a fixed mxd, whereas the name and file path of mxdA could change).

import arcpy
#define mxdA
mxd = arcpy.mapping.MapDocument(r"C:\Testing\Scratch\mxdA.mxd")
#define the dataframe from mxdA
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
#define mxdB
mxd2 = arcpy.mapping.MapDocument("Current")
#define the dataframe from mxdB
df2 = arcpy.mapping.ListDataFrames(mxd2,"Layers")[0]
#set 'newextent' to be the extent of the dataframe in mxdA
newextent = df.extent
#set the extent of the dataframe in mxdB to be the same as that of mxdA
df2.extent = newextent
#refresh the view in mxdB
arcpy.RefreshActiveView()

I am using ArcGIS (Advanced) 10.2.2

Many thanks

Dan

Tags (3)
0 Kudos
3 Replies
FreddieGibson
Occasional Contributor III

I don't believe this is possible within a supported manner using arcpy, but I have executed task similar to this using ArcObjects. Not sure if this helps, but you could into the following pages to determine if this will give you more insight on how to accomplish this.

Automating ArcGIS for Desktop Applications

http://resources.arcgis.com/en/help/arcobjects-net/conceptualhelp/index.html#/Automating_the_ArcGIS_...

LukeWebb
Occasional Contributor III

Its not what you want, but sometimes cutting our expectations is the easier option...

How about 2 root "Groups" in the table of contents, mxdA\Layers  and mxdB\Layers.... then your code just swaps the groups that are currently enabled.

WesMiller
Regular Contributor III

Following Luke Webb ​ idea you could just have two dataframes in an mxd and have one follow the other i know you could do this in one direction you may be able to in both directions but i haven't tested