I am looking for some help or if someone has a script or tool to loop through a given folder of MXD's and Create MPK files with the same name.
i don t have so much experience of creating scripts , or using the python window. I found the previous question below
enter link description here
Where it details the ESRI , help page for data managment
enter link description here
I tried inputting the python window code changing the code for my examples but i keep getting different error message. I am not sure what i am doign wrong. I m not sure about setting up the parameters for an actual tool . i was wondering if maybe someone had already done this.
Here is a script I wrote, based on the example Package Map (Data Management).
It has a few changes you'd need to be aware of. It removes any rasters from the mxds and it sets the required Summary, Description & Tags to the name of the MXD. This will change your source files so be sure to back them up.
It also just looks into a single directory and creates a small CSV file detailing any errors with certain mxds.
To stop rasters from being removed comment out lines 54-58.
This script is ran from the windows command line with
python so you will need to ensure that the python.exe is included with ArcGIS is added to your system PATH. Most likely
# Import the required python modules import arcpy from arcpy import env import os import os.path import glob import string import traceback # Set some variables for the input MXDs print 'Setting Paths' path = raw_input('File Path to Folder Containing MXDs : ') print path mxdList = glob.glob(os.path.join(path, '*.mxd')) print 'Paths Set' env.workspace = path arcpy.env.scratchWorkspace = path env.overwriteOutput = True arcpy.gp.overwriteOutput = True outputcsv = path + "OutputLog_MXDs.csv" outFile = open(outputcsv, "w") outFile.write("MXD" + "," + "Status" + "," + "Error" + " ") successcount = 0 failcount = 0 # Module to set Descriptions, Summary and Tags for the mxd. for filename in mxdList: try: mxdname = filename mxd = arcpy.mapping.MapDocument(filename) mxdleft = str(string.lstrip(filename, path)) mxdname = str(string.rstrip(mxdleft, ".mxd")) print 'Processing ' + mxdname + ' ' mxd.description = mxdname print "Description = " + mxd.description mxd.summary = mxdname print "Summary = " + mxd.summary mxd.tags = mxdname print "Tag = " + mxd.tags + ' ' # Save the MXD mxd.save() # Now Package the mxd # Read Data Frames, Identify Raster Layers and Remove them. print 'Reading Data Frames… ' DF = arcpy.mapping.ListDataFrames(mxd) print '… Found ' + str(len(DF)) + ' Data Frames' + ' ' for DF in arcpy.mapping.ListDataFrames(mxd): DFname = DF.name print "Processing - " + str(DFname) lyrs = arcpy.mapping.ListLayers(mxd) for lyrs in arcpy.mapping.ListLayers(mxd): if lyrs.isBroken: print lyrs.name + " is Broken." break if lyrs.isRasterLayer: print "Found Raster - " + str(lyrs) # Part to actually remove the raster, uses the data frame (DF) and the layer (lyrs) arcpy.mapping.RemoveLayer(DF, lyrs) print str(lyrs) + " Removed" # After the changes made, we need to save the MXD. mxd.save() print ' ' + "All Rasters Removed" print " " + "Packaging " + mxdname arcpy.PackageMap_management(filename, os.path.splitext(filename) + '.mpk', "CONVERT", "CONVERT_ARCSDE", "#", "ALL") print mxdname + " Packaged Successfully" successcount += 1 outFile.write(mxdname + "," + "Packaged" + "," + "None" + " ") del mxd, mxdname, DF except Exception as e: print "-----" print "Error" traceback.print_exc() error = str(e.message.split(' ')) print "Problem With " + mxdname print "Ignoring Error, Like A Boss" outFile.write(mxdname + "," + "Not Packaged" + "," + error.replace(' ',") + " ") failcount += 1 continue # End Statement to display basic statistics. print " " print "Finished" print str(successcount) + " MXDs Packaged Successfully - " + str(failcount) + " MXDs Failed" print "Check Output Log For Details" # Release the CSV logfile outFile.close()
Take a look at this page:
I gave you the 10.0 link based on your tag.
# Name: PackageMap.py # Description: Find all the map documents that reside in a specified folder and create map packages for each map document. # import system modules import os import arcpy from arcpy import env # Set environment settings env.overwriteOutput = True env.workspace = "C:/arcgis/ArcTutor/Editing" # Loop through the workspace, find all the mxds and create a map package using the same name as the mxd for mxd in arcpy.ListFiles("*.mxd"): print "Packaging " + mxd arcpy.PackageMap_management(mxd, os.path.splitext(mxd) + '.mpk', "PRESERVE", "CONVERT_ARCSDE", "#", "ALL")