With Python Add-In Wizard I created a Button which:
- looks in a specific directory for the last created/modified folder (which is created with another tool)
- saves the current mxd with a new name in this folder
- starts the new project
What I want to fulfill is, that I don't need to open ArcGIS again for starting the new mxd and instead of this open the new mxd in the current ArcGIS session. Does anybody have experience with this and can help me?
Here is my code:
import os, arcpy
class SaveNew(object):
"""Implementation for Python_Addins_addin.btn_speichernneu (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
def onClick(self):
#searching for last created/modified folder in directory
directory = r"\\VMSERV2\Geodata_Export"
newfolder = max([os.path.join(directory,d) for d in os.listdir(directory)], key=os.path.getmtime)
#set MapDocument and Saving and renaming in new folder
mxd = arcpy.mapping.MapDocument("CURRENT")
mxd.saveACopy(os.path.join(newfolder+"\NewProject"))
# open new mxd -> here I want to open the “NewProject.mxd” in the current ArcGIS session
os.startfile(os.path.join(newfolder," NewProject.mxd"))