donalkc

Getting the user to set the workspace?

Discussion created by donalkc on Jul 20, 2013
Latest reply on Jul 20, 2013 by Caleb1987
Hi all,

I've got a question. I'm trying to write a python script. As I want to automate as much as possible, I'm just wondering would it be possible to make the workspace a variable so that all that the person has to do is input the workspace location and script will then find the necessary files?

Basically, I was wondering just by setting the workspace and the output file names would it be possible to then the script to work? For example, is it possible to tell Python to use the workspace as the default out location or 'out folder path' in the case of creating the file geodatabase?

The script is rather long but here is the first bit if anybody has any ideas:

# Create file Geodatabase
# Import ArcGIS modules
import arcpy
print arcpy.ProductInfo()
# Check out the ArcGIS Spatial Analyst Extension
arcpy.CheckOutExtension("spatial")
# Need to be able to OverWrite Outputs
arcpy.env.overwriteOutput = True
# Set workspace
arcpy.env.workspace = "C:/Prog_Data"
# Set up variables
out_folder_path = "C:/Prog_Data"
out_name = "Prog.gdb"
# Execute CreateFileGDB
arcpy.CreateFileGDB_management(out_folder_path, out_name)
# Set local variables before importing shapefiles to Geodatabase
inFeatures =  ["Points.shp", "Extent.shp", "Rivers.shp", "Population.shp"]
outLocation = "Prog.gdb"
# Execute shapefile to Geodatabase
arcpy.FeatureClassToGeodatabase_conversion(inFeatures, outLocation)


I'm relatively new to Python so hopefully the above makes sense!

Thanks

Outcomes