Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Getting the user to set the workspace?

$
0
0
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:

Code:

# 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

Viewing all articles
Browse latest Browse all 2485

Trending Articles