I have an mxd with 20+ Feature Classes all with varying degrees of 'formatting' (i.e. most are organized in groups, some are filtered with definition queries, and all have their own unique symbologies).
Occasionally these layers must be updated with new data. I have written a script to automate the process of overwriting an outdated FC with new CSV data.
Here's the twist: The code works perfectly fine. A new FC is indeed produced from the information in the new CSV.
Again there are no errors with my code, but just to give you a look at what I'm doing:
arcpy.MakeXYEventLayer_management(Source_CSV, "Lng", "Lat", Temp_Layer, SR, "")
# Following line removes FC from TOC...
arcpy.FeatureClassToFeatureClass_conversion(Temp_Layer, Target_GDB, Target_FC_name, "", Field_Mapping)
# ...so I re-add it here...
addLayer = arcpy.mapping.Layer(Target_file)
arcpy.mapping.AddLayer(df, addLayer)
The problem in terms of my desired workflow is that FeatureClassToFeatureClass
removes the target FC from the map document. I want it to remain there, hence the last two lines of code. Of course when my script re-adds the FC it lacks all of its previous formatting (i.e. symbology, grouping, filtering, etc.) that it had before the tool was run.
How can I update a FC within an open mxd via a Python Script tool without having the FC be removed and thus lose all of its formatting?
Perhaps there's a tool that won't remove the target FC? XYTableToPoint
sounds like a good candidate, unfortunately it does not exist in my version of Arc (10.2.2).
Perhaps a SearchCursor / UpdateCursor combination will provide the solution I need? Just seems like a lot more code and processing time than with the above script, so wanted to check with online community before starting over.