5

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.

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?

I am using ArcGIS (Advanced) 10.2.2

EDIT: I have seen this post, unfortunately it doesn't answer my question.

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 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()
4

I don't believe python and arcpy expose that sort of functionality (I could be wrong?). You are asking to drive the map window in the second mxd based upon the first mxd, so an existing and running Application (ArcMap) is responding to events in another ArcMap session.

This is heading into the realms of ArcObjects and .Net for that using something called Automation. Another approach is to have the second mxd monitor the existence of a simple text file which holds the new extent and poll that file every few seconds, the file being created by say a button press in the first mxd.

Another method would to be create a pythonaddin tool bar with 2 buttons. One that writes the current extent to a text file say in c:\temp and second button that reads this file and resets the extent to what is in the text file. So the onus would be on the user to click both buttons to "pass" the extent from one mxd to another. As both running instances of ArcMap will have the same tool bar you would be able to do this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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