AnsweredAssumed Answered

Issue on Adding Feature to Open MXD in Real Time Using ArcPy

Question asked by behClevest on May 18, 2017
Latest reply on May 19, 2017 by behClevest

I am using this code to add a feature from GeoDatabase dataset to an open MXD file

 

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Temp\Streets.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
targetGroupLayer = arcpy.mapping.ListLayers(mxd, "Main", df)[0]
addLayer = arcpy.mapping.Layer(r"C:\Data\NetMap.gdb\Streets\OneWay")
arcpy.mapping.AddLayerToGroup(df, targetGroupLayer, addLayer, "BOTTOM")

 

This is somehow adding the `OneWay` feature class to the `Main` Group Layer at `Streets.mxd` but I have to close the map and reopen it to see the data there.

 

I tried to refresh the TOC and Active view like (As it work in IDE inside the Current Map)

 

arcpy.RefreshActiveView()
arcpy.RefreshTOC()

 

but it is not doing anything with stand-alone script and MXD. Can you please let me know if there is a way to do this?

Outcomes