Select to view content in your preferred language

Looping and Adding All Features From a File Geodatabase Dataset into Current Map

533
0
05-24-2017 03:07 PM
BehrouzHosseini
Regular Contributor

I need to add all features within a dataset called MainSt in a file geodatabase which is stored at following directory

C:/Temp/Roads.gdb

to current map. using following code I am able to add them one by one but can you please let me know how I can loop and add them dynamically

    mxd = arcpy.mapping.MapDocument("CURRENT")
    df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
    targetGroupLayer = arcpy.mapping.ListLayers(mxd, "Main Streets", df)[0]
    addLayer = arcpy.mapping.Layer(r"C:\Temp\Roads.gdb\MainSt\trace_Fittings")
    arcpy.mapping.AddLayerToGroup(df, targetGroupLayer, addLayer, "BOTTOM")
    arcpy.RefreshActiveView()
    arcpy.RefreshTOC()

can you please let me know how to do this? 

0 Kudos
0 Replies