AnsweredAssumed Answered

Model Builder to Python: Batch Mode

Question asked by lavpizzo on Jun 6, 2012
Latest reply on Jun 7, 2012 by lavpizzo

I created a model using model builder, and have exported it as a python script. What I am trying to do, by using the for loop, is have it run in batch mode for a series of .txt files that are tables. I am trying to have it so that the end result its 2 separate shape files, one that has been created for the starting latlon, and the other for the endlatlon (with the values all coming from 4 separate columns in the .txt file). I have run into a lot of difficulties trying to create a python script that will run in batch mode ...

I am very new to python (as I'm sure you are able to tell by the code), and would appreciate any feedback as to how to use this model that has been exported from model builder by using python and running in batch mode.


 # 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()