This seems like it should be easy, but for some reason I can't figure it out. Is there a way to implement a python add-in that runs on Arcmap startup that opens a specific mxd, as opposed to an empty one? I know you can do lots of different things on startup with addins, but I haven't been able to find anything at all on simply running one that opens a specific mxd. Any feedback would be appreciated!
this is what i've tried so far (as an application extension addin), but it's not working. I also tried it without the open._doc_ bit:
import arcpy
import pythonaddins
import os
class Verbandsgebiet(object):
"""Implementation for Verbandsgebiet_addin.add (Extension)"""
def __init__(self):
# For performance considerations, please remove all unused methods in this class.
self.enabled = True
def startup(self):
mxd = arcpy.mapping.MapDocument(r"E:\Programme\ArcGIS\Desktop 10.2\Templates\mymxd.mxd")
open.__doc__(mxd)
return
The responses in this thread will be useful. You can't directly modify the current MXD, but if you're OK with opening a new session, you can do something like:
os.startfile(mxd_path)
If you do this, you won't need to use the arcpy.mapping call, just point it at the actual path of your MXD file.
Thanks Shaun, I'll check that thread out and see what shakes out...
ok, so i tried the os.startfile(mxd_path) bit within the extension add-in, and the result is that two instances of Arc always open -- a blank mxd and then mxd_path. Another problem is that multiple instances of mxd_path open, seemingly without end. I actually have to shut the machine down to get it to stop opening instances of mxd_path.
my add-in code currently looks like this:
import arcpy
import pythonaddins
import os
class ExtensionClass1(object):
"""Implementation for mxd_addin.extension2 (Extension)"""
def __init__(self):
# For performance considerations, please remove all unused methods in this class.
self.enabled = True
def startup(self):
os.startfile('mxd_path)