Select to view content in your preferred language

Py 2.4 - using sys.argv with gp.Feature Class to Coverage

1462
11
02-07-2012 06:58 AM
DebraGajdos
Deactivated User
Hello everyone,

I am trying to put the gp tool into a script (see my post about os.walk and sys.argv). The proccessing tool looks like this in script form:

# Import system modules
import sys, string, os, arcgisscripting

# Create the Geoprocessor object
gp = arcgisscripting.create()

# Set the necessary product code
gp.SetProduct("ArcInfo")

# Load required toolboxes...
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Conversion Tools.tbx")

# Script arguments..

##lines_shp = sys.argv[1]

lines_shp = "C:\\test\\lines.shp"

# Local variables...

# Process: Feature Class To Coverage...
gp.FeatureclassToCoverage_conversion("C:\\test\\lines.shp ARC", lines_cov, "", "DOUBLE")



This works when I run it in IDLE ver 1.1.1.

But when I try to use the sys.arg like this:

# Script arguments..

lines_shp = sys.argv [1]

##lines_shp = "C:\\test\\lines.shp"

# Local variables...

# Process: Feature Class To Coverage...
gp.FeatureclassToCoverage_conversion("lines_shp ARC", linesCopy_cov, "", "DOUBLE")




I get this error:

Traceback (most recent call last):
File "C:/scripts/FC to Cov script.py", line 29, in ?
gp.FeatureclassToCoverage_conversion("lines_shp ARC", linesCopy_cov, "", "DOUBLE")
NameError: name 'linesCopy_cov' is not defined
>>>


So I guess my question is, why does FC to Coverage only play nice if the path is hard coded into the gp line? I've written other scripts and used sys.argv with no problem...

Thanks in Advance.
Tags (2)
0 Kudos
11 Replies
DebraGajdos
Deactivated User
Curtis and R.D. - thanks for those last thoughts.  I'll definitly try the path walk with a model.  Would be faster than messing with the script.  I appreciate you taking the time to work through my newbie problems. 

As for version 10 - I had to fight just to get 9.3 last year.  We'll have to see how long it will take my bosses to agree to version 10!
0 Kudos
DebraGajdos
Deactivated User
Hi Everyone,

I put the feature class to coverage gp tool into my path walk script.  First I tested everything with a different GP tool, AddField management.  It worked great.  Then I tried it with Feature Class to Coverage.  It doesn't want to work.  So, here is the code.  Your thoughts and suggestions are most appreciated:
 
import arcgisscripting, sys, string, os

gp = arcgisscripting.create()

gp.SetProduct("ArcInfo")

# Load required toolboxes...
gp.AddToolbox("C:\\Program Files\\ArcGIS\\ArcToolbox\\Toolboxes\\Conversion Tools.tbx")


try:
    def treeDir (arg, dirpath, basenames):
        gp.workspace = dirpath
        lines_list = []
        for f in basenames:
             if f == "lines.shp":
               fullf = os.path.join(dirpath,f)
                print "file=" + fullf 
                              
                #Process: Feature Class To Coverage...
                try:
                    gp.FeatureclassToCoverage_conversion(fullf+"ARC", lines_cov, "", "DOUBLE")
                except:
                      print ("gp didn't work correctly")
                                      
                    #Add A Completion Message

                else:
                 print ("Well done.")

    root = "Q:\\test\\ "  #sys.argv [1]
    os.path.walk(root,treeDir,None)
except:
    print ("Something went wrong.")
 
0 Kudos