Je commence tout juste à entrer dans les scripts Python pour le travail.
Je crée actuellement un script pour automatiser un processus.
Fondamentalement, il demande à l'utilisateur le nom du client, obtient une projection si disponible, crée un répertoire sur le lecteur C: pour le client, crée une géodatabase fichier spécifique au client, crée le jeu de données requis et crée des classes d'entités spécifiques aux données des clients. Finalement, il ajoutera également les champs requis à chaque classe d'entités et probablement d'autres choses.
J'ai commencé cela sans vraiment connaître la bonne étiquette des scripts Python pour ArcMap. Mais ce que j'ai créé jusqu'à présent ne fonctionnera qu'en dehors d'ArcMap, je crois.
Est-ce acceptable?
Au lieu d'obtenir une entrée utilisateur via arcpy.getparamaterastext (), que je viens de découvrir, j'utilise raw_input ().
Est-ce correct?
Cela fonctionne, je ne suis simplement pas sûr que ce soit une bonne façon de faire des scripts.
Voici le code que j'ai jusqu'à présent.
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.")
J'ai encore du travail à faire, comme l'ajout des champs nécessaires.