I have a need for some ArcPy code that will allow me to move feature classes in my File Geodatabase to the Table of Contents in my ArcGIS Pro project. However, I have no idea how to do this and I can not find any examples of this online.
Is this possible? Could someone please show me how to do this?
Check out arcpy.mapping.AddLayer()
Thanks for the quick response Blake. I'm not sure this is exactly what I'm looking for though.
Maybe I should explain a little more. Ideally, it would be great if after I run my summarize within script, it takes the output feature class and adds it to the contents pane. For example:
# import system modules
import arcpy
# Set environment settings
arcpy.env.workspace = 'C:/data/city.gdb'
# Set local variables
polys = 'neighborhoods'
points = 'crimes'
outFeatureClass = 'crimes_aggregated'
keepAll = 'KEEP_ALL'
sumFields = [['Damages', 'SUM'], ['VICTIM_AGE', 'MEAN']]
addShapeSum = 'ADD_SHAPE_SUM'
groupField = 'Crime_type'
addMinMaj = 'ADD_MIN_MAJ'
addPercents = 'ADD_PERCENT'
outTable = 'crimes_aggregated_groups'
arcpy.SummarizeWithin_analysis(polys, points, outFeatureClass, keepAll,
sumFields, addShapeSum, '', groupField,
addMinMaj, addPercents, outTable)
So after the "arcpy.SummarizeWithin_analysis()" I would like to add a piece of code that would take that feature class that was just created and move it to the contents pane.
Your options at the global level are to 'add results to display' in your overall settings, or MakeFeatureLayer.
Generally results are added to the display IF the project is running and the script is attached to a tool. If you are running a standalone script, then make a layer file and use Blake's suggestion.