Adding Script Output to Map

134
2
04-09-2021 11:59 AM
Labels (1)
Rlangem
New Contributor

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)

0 Kudos
2 Replies
DanPatterson
MVP Honored Contributor

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


... sort of retired...
0 Kudos
Rlangem
New Contributor

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)

0 Kudos