Select to view content in your preferred language

Open mxd with python add-in?

3201
4
08-27-2014 05:45 AM
TrilliumLevine1
Deactivated User

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!

0 Kudos
4 Replies
TrilliumLevine1
Deactivated User

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

0 Kudos
ShaunWalbridge
Esri Regular Contributor

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.

TrilliumLevine1
Deactivated User

Thanks Shaun, I'll check that thread out and see what shakes out...

0 Kudos
TrilliumLevine1
Deactivated User

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)

0 Kudos