import arcpy, os, sys, traceback from os import path as p arcpy.env.workspace = ws = r'C:\testing' # Variables xls = r'C:\testing\Cedar_Network.xlsx\Sheet1$' spa_ref = r'C:\Program Files (x86)\ArcGIS\Desktop10.0\Coordinate Systems\Projected Coordinate Systems\State Plane\NAD 1983 (US Feet)\NAD 1983 StatePlane Iowa South FIPS 1402 (US Feet).prj' layer = 'XY_Event' outfold = r'C:\testing\test.gdb' output = p.join(outfold, 'control_points') try: arcpy.MakeXYEventLayer_management(xls, 'EASTING', 'NORTHING', layer, spa_ref) arcpy.CopyFeatures_management(layer, output) print 'Feature Class Created' except: # Get the traceback object tb = sys.exc_info() tbinfo = traceback.format_tb(tb) # Concatenate information together concerning the error into a message string pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()) msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages(2) + "\n" # Return python error messages for use in script tool or Python Window arcpy.AddError(pymsg) arcpy.AddError(msgs) # Print Python error messages for use in Python / Python Window print pymsg + "\n" print msgs
Thanks for that!! Im reading about relationship classes, but that may be kinda pointless since Ive only got ArcView licenses to work with. Im going to try to play with the scripting option. My boss at my old job wanted to set something up like that, but we never got around to it. Im not really good at understanding the basics of scripting languages, so I have a hard time writing things, but if I need to run a simple process, I can usually get that done.
Did the coordinate system .prj files move somewhere else for 10.1? I cant seem to find them. Also, will this work if 1. there are files in the GDB with the same name as the ones I want to put in (ie, can it replace existing files?), and 2. if the Excel table is not on my local drive? Thank you!!
sr = arcpy.SpatialReference(26776) # OR (I think) sr = arcpy.SpatialReference('NAD 1927 StatePlane Iowa South FIPS 1402 (US FEET)')
arcpy.env.outputCoordinateSystem = arcpy.SpatialReference('NAD 1927 StatePlane Iowa South FIPS 1402 (US FEET)')
# set the environment setting to overwrite output arcpy.env.overwriteOutput = True # OR table = r'G:\Some\Path\Table' if arcpy.Exists(table): arcpy.Delete_management(table) # Copy table to geodatabase after deleting original here
try: arcpy.MakeXYEventLayer_management(xls, 'LONGITUDE', 'LATITUDE', layer) arcpy.CopyFeatures_management(layer, output) print 'Feature Class Created'