I am trying to create a script tool to automate this process, eventually it will be used for batch processing but at the moment I can't even get test data to work. This is pretty basic at the moment, and I know it can be done through ArcGIS, but I would like to develop a python script for processing. My code is as below: It completes without error, but I am expecting the creation of a feature layer (even better would be a feature class with POINT geometry). I can't find or access the output of the SaveToLayerFile step.
I apologise for the messiness of the code, I've been trying to beat this for 2 days now.. Any help would be appreciated.
#Import libraries import arcpy import os import sys arcpy.env.overwriteOutput = True #Set workspace home = arcpy.env.workspace arcpy.env.workspace = arcpy.GetParameterAsText(0) mxd = arcpy.mapping.MapDocument("Current") df = arcpy.mapping.ListDataFrames(mxd, "*") #Create spatial reference object prjFile = arcpy.GetParameterAsText(2) spatialRef = arcpy.SpatialReference(prjFile) arcpy.AddMessage('Setting Spatial Reference') #Set Excel Datasheet for Migration TEST = arcpy.GetParameterAsText(1) try: # Process: Table to Table Conversion with destination variable FarmerTable = 'Farmers1' arcpy.AddMessage('Migrating Data...') arcpy.TableToTable_conversion (TEST, home, FarmerTable) except: arcpy.GetMessages() # Set local variables in_layer = "FarmerLyr" out_layer = "FarmerLyr.lyr" out_layer0 = "FarmerLyr" try: #Make XY Events of each Farmer arcpy.AddMessage('Creating Features...') result = arcpy.MakeXYEventLayer_management(FarmerTable, "X", "Y", out_layer0, spatialRef, "") result.getOutput(0) = out_layer0 arcpy.AddMessage(arcpy.GetCount_management(out_layer0)) arcpy.AddMessage('Successfully Created Features') # Execute SaveToLayerFile arcpy.SaveToLayerFile_management(out_layer0, out_layer, "ABSOLUTE") except: print arcpy.GetMessages()