run python script from custom toolbox

474
1
06-20-2011 07:14 AM
bogdanpalade1
New Contributor III
hello,

I am trying to add a script to a toolbox in order to run it more confortably. The script will repair data sources (for data moved from initialFolder to finalFolder) within several mxd files (present in folderPath) and is mainly a copy from the ArcGis help file. I will list it here:

import arcpy, os

folderPath = arcpy.GetParametersAsText(0)
initialFolder = arcpy.GetParametersAsText(1)
finalFolder = arcpy.GetParametersAsText(2)
for filename in os.listdir(folderPath):
    fullpath = os.path.join(folderPath, filename)
    if os.path.isfile(fullpath):
        basename, extension = os.path.splitext(fullpath)
        if extension.lower() == ".mxd":
            mxd = arcpy.mapping.MapDocument(fullpath)
            mxd.findAndReplaceWorkspacePaths(initialFolder, finalFolder)
            mxd.save()

del mxd



The problem is that while it runs perfectly as python script with python idle, it would not run as a script in arcgis toolbox.
I added the script to a new toolbox and I defined the parameters as is follows:

folderPath = folder type, input
initialFolder = folder type, input
finalFolder = folder type, input.

I also tried replacing the folder type with workspace type but still does not work.

when I run the script I get the error: "Error in executing cmd.exe "path to the script. ...Failed to execute script".

Do you know what may be the problem?

Thank you very much,

Bogdan
Tags (2)
0 Kudos
1 Reply
bogdanpalade1
New Contributor III
nevermind this thread and sorry for the trouble. The script runs fine, I had forgot to add the .py extension to my script.

Cheers,

Bogdan
0 Kudos