I've written a simple python script that allows me to quickly create a copy of a template Mxd, pointing to different shapefiles. The user specifies the new location, a name for the new mxd, then the folder that the shapefiles are stored in and the name of a point, polyline, and polygon shapefile. This script works fine.
newFilePath = r"X:\folder\outputfolder" mxdName = "New_MXD" shpFolder = r"X:\folderpath\templates" shape_points = "input_P" shape_polylines = "input_L" shape_polygons = "input_G" template_points = r"X:\folderpath\template_P.shp" template_polylines = r"X:\folderpath\template_L.shp" template_polygons = r"X:\folderpath\template_G.shp" import arcpy MyMXD = r"X:\folder\template.mxd" mxd = arcpy.mapping.MapDocument(MyMXD) outMxd = newFilePath +"\\"+ mxdName+".mxd" for lyr in arcpy.mapping.ListLayers(mxd): if lyr.supports("DATASOURCE"): if lyr.dataSource == template_points: print lyr.dataSource lyr.replaceDataSource(shpFolder, 'SHAPEFILE_WORKSPACE', shape_points) print "data replaced" if lyr.dataSource == template_polylines: lyr.replaceDataSource(shpFolder, 'SHAPEFILE_WORKSPACE', shape_polylines) if lyr.dataSource == template_polygons: print lyr.dataSource lyr.replaceDataSource(shpFolder, 'SHAPEFILE_WORKSPACE', shape_polygons) mxd.saveACopy(outMxd)
I would like to turn this script into a tool that my colleagues can run without having to open the script. I've seen Esri guides for adding scripts to a toolbox, and for creating Python Toolboxes, but its not clear which I need to do.
I've tried the first option, and replaces the first block with:
NewFilePath = arcpy.GetParameterAsText(0) mxdName = arcpy.GetParameterAsText(1) shpFolder = arcpy.GetParameterAsText(2) shape_points = arcpy.GetParameterAsText(3) shape_polylines = arcpy.GetParameterAsText(4) shape_polygons = arcpy.GetParameterAsText(5)
When I tick "Run Python script in process" the script runs but nothing happens. When I untick this and tick "show command window when excecuting script" the script fails and I get:
ERROR 000714: Error in script ViewSismageExport.
Is setting up parameters more complicated than this?
I first tried setting the folders to be folders and the shapefiles to be shapefiles, but I've not got everything as string, with it still not working.