Dynamically add features to map

250
0
02-01-2021 07:40 AM
Labels (1)
PenelopeMitchell2
New Contributor II

Hello,

I am trying to dynamically add the contents of a feature dataset to a map in Pro v 2.7.

To achieve this, my understanding of the workflow is that I need to list the features in the feature dataset ('ResultsPath' in code snippet below), then convert to layer, save as a layer file, then add layer. The code below runs without errors, but nothing happens--nothing is added to the map and no layer files are generated.  Any pointers? Thanks in advance. 

 

#Lists the feature classes in the Results Feature Dataset
#Dynamically convert to layer and add to map.
#Code working, but nothing happening? 
m = aprx.listMaps()[0]
for fc in arcpy.ListFeatureClasses(ResultsPath):
    OutFile = ScratchWS + os.sep + str(fc)
    lf = arcpy.MakeFeatureLayer_management(fc, OutFile, None, None).getOutput(0)
    lyf = arcpy.management.SaveToLayerFile(lf, OutFile)
    m.addLayer(lyf, "AUTO_ARRANGE")

 

 

Tags (3)
0 Kudos
0 Replies