ledwith

Script works in IDLE but not ArcGIS

Discussion created by ledwith on Dec 20, 2010
Latest reply on Dec 21, 2010 by niklas.norrthonesri-se-esridist
I have a simple script that checks a folder for .rar files, unrars them and then converts any ascii files to raster.

It works fine in IDLE. Running the same script from ArcToolbox raises an error.

Here's the code:

import arcpy
from arcpy import env
import os
import sys
import chilkat

aSCIICat = arcpy.GetParameterAsText(0)
if aSCIICat == '#' or not aSCIICat:
    aSCIICat = r"P:\NNH_oversvamning_M102567\indata\laserdata\2mgrid\malmoe\10A001\Backup\RAR"
outCat = arcpy.GetParameterAsText(1)
if outCat == '#' or not outCat:
    outCat = aSCIICat
env.workspace = aSCIICat
env.overwriteOutput = "TRUE"
catName = os.path.abspath(aSCIICat)

rarFiles = arcpy.ListFiles("*.rar")

try:
    for rarFile in rarFiles:
        rar = chilkat.CkRar()
        toOpen = catName + "\\" + rarFile
        text = str(toOpen)
        success = rar.Open(text)
        if (success != True):
            print rar.lastErrorText()
            sys.exit()
        success = rar.Unrar(outCat)
        if (success != True):
        print rar.lastErrorText()
except Exception as e:
    print e.message
    arcpy.AddError(e.message)

ascFiles = arcpy.ListDatasets("*.asc")

try:
    for ascFile in ascFiles:
        ascFileN = catName + "\\" + ascFile
        print "Processing: " + ascFile
        outRaster = outCat + "\\" + ascFile[:-3] + "img"
        arcpy.ASCIIToRaster_conversion(ascFileN, outRaster, "FLOAT")
except Exception as e:
    print e.message
    arcpy.AddError(e.message)

print "All done"

-----------------------

Chilkat is a python module that allows the .rar files to be opened and uncompressed.

I figure there are two possible sources of error.

1. Importing non-standard modules in ArcGIS is not straightforward (as opposed to IDLE), or
2. The GetParameterAsText doesn't work as it should when running a script from ArcToolbox.
-in particular, the Python code assigning a default value appears to be completely ignored when running in ArcToolbox. The default values must be assigned via Properties or not at all.

Anyone familiar with this type of problem? Any help?

Outcomes