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)


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.


1 Answer 1


Setting the parameters as you have done is the correct thing to do. The order of parameters in your code (0 to 5) must be the same as the order of the parameters when you are wiring in your script as a script tool.

I note that your newFilePath now starts with a capital N, python is case sensitive.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.