# Import system modules import sys, string, os, arcgisscripting # Create the Geoprocessor object gp = arcgisscripting.create(9.3) # Load required toolboxes... gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx") # Allows geoprocessing tools to overwrite the output if it already exists. gp.OverWriteOutput = True # Set the Environment Variables gp.Workspace = r"C:\TST_Folder" # List the .txt file input tables table = gp.ListTables("*txt") try: # For each .txt table found in the Workspace, perform the following series of tasks for each .txt file for table in Workspace: # Removes the file extension tableName = table[:-4] # Reports which table is being processed gp.addmessage("Processing table" + str(tableName)) # Process: Make XY Event Layer (E_LATLON)...Save file as the tableName with tmp1 as the suffix gp.MakeXYEventLayer_management(tableName, "LON", "LAT", tableName + (str(tmp1)), "GEOGCS['GCS_WGS_1984',DATUM") # Process: Copy Features (E_LATLON)...Save file as the tableName with tmp1 as the suffix gp.CopyFeatures_management(tableName + (str(tmp1)), tableName + (str(tmp1.shp)), "", "0", "0", "0") # Process: Project (E_LATLON)...Save file as the tableName with _e as the suffix gp.Project_management(tableName + (str(tmp1.shp)), tableName + (str(_e.shp)), "PROJCS['LCC']) # Process: Add Field onto(E_LATLON)... gp.AddField_management(tableName + (str(_e.shp)), "Title", "FLOAT", "6", "4", "", "", "NON_NULLABLE", "NON_REQUIRED", "") # Process: Calculate Field onto (E_LATLON)... gp.CalculateField_management(tableName_e.shp, "Title", "Sqr ( X^2 )", "VB", "") # Process: Make XY Event Layer (S_LATLON)... Save file as the tableName with tmp as the suffix gp.MakeXYEventLayer_management(tableName, "sLon", "sLat", tableName_tmp, "GEOGCS['GCS_WGS_1984',DATUM") # Process: Copy Features (S_LATLON)... Save file as the tableName with tmp as the suffix gp.CopyFeatures_management(tableName + (str(tmp)), tableName + (str(tmp.shp)), "", "0", "0", "0") # Process: Project (S_LATLON)... Save file as the tableName with _s as the suffix gp.Project_management(tableName_tmp.shp, tableName + (str(_s.shp)), "PROJCS['LCC']) except: #If an error occurred while running the script, then print the messages print gp.GetMessages()
Solved! Go to Solution.
# Set the Environment Variables gp.Workspace = r"C:\TST_Folder" #### < THIS IS A GP VARIABLE # List the .txt file input tables table = gp.ListTables("*txt") #### < THIS IS THE LIST YOU SHOULD ITTERATE try: # For each .txt table found in the Workspace, perform the following series of tasks for each .txt file for table in Workspace: #### Workspace CANNOT BE ITTERATED, and YOU ARE REASSIGNING table # Removes the file extension tableName = table[:-4] #### IN VIEW OF THE LINE ABOVE, THIS MAKES NO SENSE #### IF table WAS STILL A LIST, YOU WOULD BE CHOPPING OFF THE LAST FOUR ITEMS
# Set the Environment Variables gp.Workspace = r"C:\TST_Folder" # List the .txt file input tables table = gp.ListTables("*txt") try: for t in table: # Removes the file extension tableName = t[:-4] # Reports which table is being processed gp.addmessage("Processing table" + str(tableName))
import os tableName = os.path.splitext(table)[0]
# List the .txt file input tables table = gp.ListTables("*txt") print table try: for t in list(table): # Removes the file extension tableName = os.path.splitext(t)[0] # Reports which table is being processed gp.addmessage("Processing table" + str(tableName)) # Process: Make XY Event Layer (endLatLon)... gp.MakeXYEventLayer_management(tableName, "eLon", "eLat", tableName + (str(_tmp1)), "Coordinate System") # Process: Copy Features (endLatLon)... gp.CopyFeatures_management(tableName_tmp1), tableName + (str(_tmp1a)), "", "0", "0", "0") # Process: Project (endLatLon)... gp.Project_management(tableName_tmp1a, tableName + (str(_e.shp)), "PROJCS['LCC')]") # Process: Add Field onto(endLatLon)... gp.AddField_management(tableName_e.shp), "Vari", "FLOAT", "3", "2", "", "", "NON_NULLABLE", "NON_REQUIRED", "") # Process: Calculate Field onto (endLatLon)... gp.CalculateField_management(tableName_e.shp, "Vari", "Sqr ( x^2 )", "VB", "") # Process: Make XY Event Layer (startLatLon)... gp.MakeXYEventLayer_management(tableName, "sLon", "sLat", tableName + (str(_tmp)), "Coordinate System") # Process: Copy Features (startLatLon)... gp.CopyFeatures_management(tableName_tmp), tableName + (str(_tmpa)), "", "0", "0", "0") # Process: Project (startLatLon)... gp.Project_management(tableName_tmpa.shp, tableName + (str(_s.shp)), "PROJCS['LCC')]") except: #If an error occurred while running the script, then print the messages print gp.GetMessages()
# List the .txt file input tables table = gp.ListTables("*txt") print table try: for t in list(table): # Removes the file extension tableName = os.path.splitext(t)[0] # Reports which table is being processed gp.addmessage("Processing table" + str(tableName)) # Local variables... tableName_tmp = tableName + str("_tmp") tableName_tmp1 = tableName + str("_tmp1") tableName_e = tableName + str("_e.shp") tableName_tmp1A = tableName + str("_tmp1A.shp") tableName_s = tableName + str("_s.shp") tableName_tmpA = tableName + str("_tmpA.shp") # Process: Make XY Event Layer (endLatLon)... gp.MakeXYEventLayer_management(t, "eLon", "eLat", tableName_tmp1, "GeographicCoordinates") # Process: Copy Features (endLatLon)... gp.CopyFeatures_management("tableName_tmp1.shp", tableName_tmp1A, "", "0", "0", "0") # Process: Project (endLatLon)... gp.Project_management("tableName_tmp1A.shp", tableName_e, "ProjectedCoordinates") # Process: Add Field onto(endLatLon)... gp.AddField_management("tableName_e.shp", "Vel_Value", "FLOAT", "6", "4", "", "", "NON_NULLABLE", "NON_REQUIRED", "") # Process: Calculate Field onto (endLatLon)... gp.CalculateField_management("tableName_e.shp", "Vel_Value", "x^2 ", "VB", "") # Process: Make XY Event Layer (startLatLon)... gp.MakeXYEventLayer_management(tableName, "sLon", "sLat", tableName_tmp, "GeographicCoordinates") # Process: Copy Features (startLatLon)... gp.CopyFeatures_management("tableName_tmp.shp", tableName_tmpA, "", "0", "0", "0") # Process: Project (startLatLon)... gp.Project_management("tableName_tmpA.shp", tableName_s, "ProjectedCoordinates") except: #If an error occurred while running the script, then print the messages print gp.GetMessages()
"tableName_tmp1.shp"
tableName_tmp1