2

I am currently trying to make my (working) standalone script into an ArcGIS tool so I'm not the only person in my office that can use it. It selects all the data within a specified location and copies it to a new geodatabase. Since replacing my old variables with sys.argv[#], new errors keep popping up. The following section of code is giving me problems right now:

out_folder_path_gdb = sys.argv[1]
out_name_gdb = sys.argv[2]
out_name_fc = "buffer_point"
geometry_type = "POINT"
has_m = "DISABLED"
has_z = "DISABLED"
sr = sys.argv[3]
fc = out_folder_path_gdb + "\\" + out_name_gdb + "\\" + out_name_fc
lyrlst = []
######################
# Create geodatabase #
######################
try:
 arcpy.CreateFileGDB_management(out_folder_path_gdb, out_name_gdb)
except:
 print "Geodatabase already exists."
 arcpy.AddIDMessage("Error", 12, out_name_gdb)
 sys.exit(0)
##########################
# Create point to buffer #
##########################
arcpy.env.overwriteOutput = True
arcpy.CreateFeatureclass_management(out_folder_path_gdb + "\\" + out_name_gdb, out_name_fc, geometry_type, "", has_m, has_z, sr)
############################################
# Sets given coordinates as a point object #
############################################
rowInserter = arcpy.InsertCursor(fc)
x = sys.argv[4]
y = sys.argv[5]
pointGeometry = arcpy.Point(x,y)

When running the tool within Arc, I get the following error: : Failed to execute. Parameters are not valid. ERROR 000732: Feature Class Location: Dataset C:\Documents and Settings\benoyn\Desktop\DaS GIS work\data_extraction_test\pleasepleaseplease does not exist or is not supported Failed to execute (CreateFeatureclass).

The only reason I can think of for this error is the spaces in "Documents and Settings".

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Feb 15, 2013 at 23:43
1
  • 2
    Have you tried testing it in a location without spaces? Such as "C:\Temp"? Commented Feb 16, 2013 at 0:46

1 Answer 1

4

It appears the error is encountered on the line for CreateFeatureclass, that the location is bad:

C:\Documents and Settings\benoyn\Desktop\DaS GISwork\data_extraction_test\pleasepleaseplease

And this should have been a string made of: out_folder_path_gdb + "\" + out_name_gdb

Note that the end component of that string should have been a gdb and it appears it is not (pleasepleaseplease is not a gdb), so that's is what you need to check - I'd particularly look at what is happening where the gdb is created, with the out_name_gdb param...verify that it is created properly based on your other string params.

Also, not saying it won't work with sys.argv to fetch user input, but try to use arcpy.GetParameterAsText(0) and see if that works better (start indexing the 'get' variables from zero (0) -- confirm with some print statements that you're receiving those params properly - I usually form raw strings whereever possible on pathnames and make sure extensions get appended (the .gdb), i.e., r'\server\folder\subfolder\name.gdb\nameFC'

Not sure if you have any '\' in your script, but if so, python trips -- you can instead use os.sep to combine path components or use the os.path.join technique.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
answered Feb 16, 2013 at 1:55
1
  • It might not hurt to check if sys.argv[1] (or GetParameterAsText(0)) .endswith('.gdb') if others will be using this. Also check that the gdb doesn't already exist. Commented Feb 27, 2015 at 21:15

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.