import arcpy #Define message constants so they may be translated easily unknown_projection = "Unknown" # Get the feature class to describe # featureClass = arcpy.GetParameterAsText(0) desc = arcpy.Describe(featureClass) #Loop through each dataset and describe projection. for dataset in inDatasets: try: #Describe input dataset to check if a projection is already defined. dsc_Dataset = ConversionUtils.gp.Describe(dataset) cs_Dataset = dsc_Dataset.SpatialReference #Check if a projection is already define for the input dataset. if cs_Dataset.Name != unknown_projection: ConversionUtils.gp.AddWarning(msgPrjAlreadyDefine) # Print SpatialReference object properties SR = desc.spatialReference print SR.name # shows results in commandline of IDLE print SR.exportToString() # Show results in geoprocessing tool dialog arcpy.AddMessage(SR.name) arcpy.AddMessage(SR.exportToString())
import arcpy #Define message constants so they may be translated easily unknown_projection = "Unknown" #Loop through each dataset and describe projection. inDatasets = arcpy.ListFeatureClasses() for dataset in inDatasets: try: # Describe each fc desc = arcpy.Describe(dataset) #Describe input dataset to check if a projection is already defined. dsc_Dataset = ConversionUtils.gp.Describe(dataset) cs_Dataset = dsc_Dataset.SpatialReference #Check if a projection is already define for the input dataset. if cs_Dataset.Name != unknown_projection: ConversionUtils.gp.AddWarning(msgPrjAlreadyDefine) # Print SpatialReference object properties SR = desc.spatialReference print SR.name # shows results in commandline of IDLE print SR.exportToString() # Show results in geoprocessing tool dialog arcpy.AddMessage(SR.name) arcpy.AddMessage(SR.exportToString()) except: arcpy.AddMessage("ERROR!")
<type 'exceptions.RuntimeError'>: ERROR 000638: Workspace not set for GeoProcessor.
Failed to execute (BatchDescribeProjection).
import arcpy arcpy.env.workspace = "T:\WORK FOLDER" #Define message constants so they may be translated easily unknown_projection = "Unknown" #Loop through each dataset and describe projection. inDatasets = arcpy.ListFeatureClasses() for dataset in inDatasets: try: # Describe each fc desc = arcpy.Describe(dataset) #Describe input dataset to check if a projection is already defined. dsc_Dataset = ConversionUtils.gp.Describe(dataset) cs_Dataset = dsc_Dataset.SpatialReference #Check if a projection is already define for the input dataset. if cs_Dataset.Name != unknown_projection: ConversionUtils.gp.AddWarning(msgPrjAlreadyDefine) # Print SpatialReference object properties SR = desc.spatialReference print SR.name # shows results in commandline of IDLE print SR.exportToString() # Show results in geoprocessing tool dialog arcpy.AddMessage(SR.name) arcpy.AddMessage(SR.exportToString()) except: arcpy.AddMessage("ERROR!")
Executing: BatchDescribeProjection 'T:\WORK FOLDER\DEN_MP_DIA.shp'
Start Time: Fri Feb 25 08:15:38 2011
Running script BatchDescribeProjection...
ERROR!
ERROR!
ERROR!
ERROR!
ERROR!
ERROR!
ERROR!
ERROR!
ERROR!
ERROR!
ERROR!
ERROR!
ERROR!
ERROR!
ERROR!
Completed script BatchDescribeProjection...
Succeeded at Fri Feb 25 08:15:39 2011 (Elapsed Time: 1.00 seconds)
In general, yes.
Do you always have to set a workspace?
You can run script tools from anywhere on your network but you'll have to change the path (workspace) in your script to where your data is.
or can script tools run data from anywhere on your network?
arcpy.env.workspace = "T:\\WORK FOLDER"
Executing: BatchDescribeProjection 'T:\WORK FOLDER\DEN_MP_DIA.shp';'T:\WORK FOLDER\dirt_spcs.shp'
Start Time: Fri Feb 25 14:38:27 2011
Running script BatchDescribeProjection...
ERROR!
ERROR!
ERROR!
ERROR!
ERROR!
ERROR!
ERROR!
ERROR!
ERROR!
ERROR!
ERROR!
ERROR!
ERROR!
ERROR!
ERROR!
Completed script BatchDescribeProjection...
Succeeded at Fri Feb 25 14:38:29 2011 (Elapsed Time: 2.00 seconds)
import arcpy #Loop through each dataset and describe projection. fcs = arcpy.GetParameterAsText(0) for fc in fcs: try: desc = arcpy.Describe(fc) # Print some SpatialReference object properties SR = desc.spatialReference print SR.name # shows results in commandline of IDLE print SR.exportToString() # Show results in geoprocessing tool dialog arcpy.AddMessage(SR.name) arcpy.AddMessage(SR.exportToString()) except: arcpy.AddMessage("ERROR!")
In general, yes.
There are exceptions depending "how" you are running your script, and what tools your using (at least in 9.x.) Not positive about 10.x.
You can run script tools from anywhere on your network but you'll have to change the path (workspace) in your script to where your data is.
arcpy.env.workspace = arcpy.GetParameterAsText(0)
import arcpy arcpy.env.workspace = "T:/WORK FOLDER" #Loop through each dataset and describe projection. inDatasets = arcpy.ListFeatureClasses() for dataset in inDatasets: # Describe each fc desc = arcpy.Describe(dataset) #Describe input dataset to check if a projection is already defined. dsc_Dataset = arcpy.Describe(dataset) cs_Dataset = dsc_Dataset.SpatialReference #Check if a projection is already define for the input dataset. if cs_Dataset.Name != "Unknown": arcpy.AddWarning("msgPrjAlreadyDefine") # Print SpatialReference object properties SR = desc.spatialReference print SR.name # shows results in commandline of IDLE print SR.exportToString() # Show results in geoprocessing tool dialog arcpy.AddMessage(SR.name) arcpy.AddMessage(SR.exportToString()) print "\nDone.\n"