I'm just starting to get into Python scripting for work.
I'm currently creating a script to automate a process.
Basically, it asks the user the client name, gets a projection if available, creates directory on C: drive for client, creates file geodatabase specific to client, creates required dataset, and creates feature classes specific to clients data. Eventually, it will also add the required fields to each feature class and probably some other things.
I started this not really knowing the proper etiquette of Python scripting for ArcMap. But what I've created so far will only run outside ArcMap I believe.
Is this acceptable?
Instead of getting user input through arcpy.getparamaterastext(), which I just found out about, I'm using raw_input().
Is this okay?
It does work, I'm just not sure if this is a proper way to do scripting.
Here's the code I have so far.
import sys
import arcpy
import os
#Records name of the client
client = raw_input("Enter the name of the client: (letters and underscores only) \n")
#Records filepath of client to be created
clientpath = "C:/" + client
#Inquires if projection file exists
projection = raw_input("Is there a .prj or .shp available with correct projection? Y or N \n")
#Records the projection location if available
if projection.upper() == "Y":
spatialr = raw_input("Drag the .prj or .shp here to record the filepath \n")
nspatialr = spatialr.replace('"', "")
elif projection.upper() == "N":
alert = raw_input("You must add the spatial reference manually, hit enter to continue. \n")
elif projection.upper() != "N" or "Y":
exit = raw_input("That is not a valid response. Try again. \n")
sys.exit()
#Checks if client folder exists; if not, creates one
if not os.path.exists(clientpath):
os.makedirs(clientpath)
#Variable for file geodatabase location
FGBpath = clientpath + "/" + client + ".gdb"
#Checks if client file geodatabase exists; if not, creates one
if not arcpy.Exists(FGBpath):
arcpy.CreateFileGDB_management(clientpath, client)
#Variable for dataset location
FDatasetpath = clientpath + "/" + client + ".gdb" + "/Network"
#Checks if dataset exists; if not, creates one
if not arcpy.Exists(FDatasetpath):
if projection.upper() == "Y":
arcpy.CreateFeatureDataset_management(FGBpath, "Network", nspatialr)
elif projection.upper() == "N":
arcpy.CreateFeatureDataset_management(FGBpath, "Network")
#Variable for cable feature class location
FCcablepath = clientpath + "/" + client + ".gdb" + "/Network" + "/cable"
#Checks if cable feature class exists; if not, creates one
if not arcpy.Exists(FCcablepath):
if projection.upper() == "Y":
arcpy.CreateFeatureclass_management (FDatasetpath, "cable", "POLYLINE", "", "", "", nspatialr)
elif projection.upper() == "N":
arcpy.CreateFeatureclass_management (FDatasetpath, "cable", "POLYLINE")
#Variable for splice point feature class location
FCsplicepath = clientpath + "/" + client + ".gdb" + "/Network" + "/splice_point"
#Checks if splice point feature class exists; if not, creates one
if not arcpy.Exists(FCsplicepath):
if projection == 'Y' or projection == 'y':
arcpy.CreateFeatureclass_management (FDatasetpath, "splice_point", "POINT", "", "", "", nspatialr)
elif projection == 'N' or projection == 'n':
arcpy.CreateFeatureclass_management (FDatasetpath, "splice_point", "POINT")
exit = raw_input("\n\n File geodatabase, dataset, and the cable \n and splice point feature classes successfully created. \n\n Hit enter to exit.")
I still have some work to do, like adding the needed fields.