I am trying to create a map automation tool using Python from the command line where I pull data from a web URL, add the data as a feature class, edit the symbology, and then export as a map .png file.
I am able to pull in the data, create a feature class using arcpy.management.CreateFeatureclass( ), add fields to the feature class using arcpy.management.AddField( ), and Insert the data into the feature class with arcpy.da.InsertCursor( ).
The file geodatabase feature class is showing up in the specified geodatabase within my ArcGIS Pro project, but the data is NOT being added to the map. I can manually select "Add to Current Map" but would like to automate this process. Any help would be great! When I run the same code using ArcGIS Pro's Python window, the feature class is automatically added as a Layer to the map so I am stumped as to why it is not adding it through Command Prompt (note: I am not looking to create a separate Layer file, the same issue occurs)
You need to get a reference to the map and use the addLayer method or the addDataFromPath method (see code samples at the end of this help topic, linked below).
https://pro.arcgis.com/en/pro-app/3.1/arcpy/mapping/map-class.htm
If you're running from within Pro you can use the "CURRENT" keyword to reference the map, otherwise you can provide a path to the aprx file.
Thanks for the suggestion! I do provide a path to the aprx file and set a path to output the feature class. The feature class is correctly being added to the file geodatabase within the ArcGIS Pro Project, it is just not automatically adding the data to the map as it does when I run the same code within Pro.