HI,
I have made a script tool which runs several geoprocessing functions in a row. The final result is a new feature class. At the end of the script I need it open the feature class, and then apply symbology from another layer. I have not been able to get it to open a feature class in the map from within the script. I have tried several ideas from forum but have not had nay luck. Most throw errors. The following allows the program to complete but does nothing. Thanks in advance for the help.
aprx = arcpy.mp.ArcGISProject("CURRENT")
aprxMap = aprx.listMaps()[0]
aprxMap.addDataFromPath(outpath)
MakeFeatureLayer is the usual way
Make Feature Layer (Data Management)—ArcGIS Pro | Documentation
Not sure if addDataFromPath actually makes the featurelayer or just adds the data from the project
Thanks for the quick reply. When I include that command by itself the script runs but the layer does not appear on the map. I have also tried the following, but I keep getting errors. The save layer to file say the layer does not exist, so I am not sure if it is not creating a layer or if it is not saving it in the correct workspace. As far as I can tell it is not making a layer.
aprx = arcpy.mp.ArcGISProject("CURRENT")
aprxMap = aprx.listMaps("Map")[0]
newlyr = arcpy.management.MakeFeatureLayer(outname, lyrpath)
save = arcpy.management.SaveToLayerFile(lyrname)
yieldmap = arcpy.mp.LayerFile(lyrname)
aprxMap.addLayer(yieldmap)