I have hundreds of pairs of FGDB and associated MXD files. I need to insert a graph in each mxd linked to its corresponding FGDB. No problem creating graph, but stuck on how to get graph into mxd file using arcpy. If the graph creation code is run inside the mxd manually, the graph appears, but I need to do it in the python script loop.
import arcpy workspace = r'C:\gdb_dir' workspaces = arcpy.ListFiles('*.gdb') # list of files to process for workspace in workspaces: name_prefix = workspace[0:-4] current_MXD = name_prefix + '.mxd' # this file will already exist dataSrc = r'C:\name_prefix\Sample.gdb\DetailFeatures' fieldX = 'NEAR_X' fieldY = 'NEAR_Y' graph_template = r'C:\temp\ScatterGraphTemplate.tee' out_graph_name = "ScatterTest" out_graph = r'c:\graphs\' + name_prefix + '.grf' # How to insert this into mxd? graph = arcpy.Graph() graph.addSeriesScatterPlot(dataSrc, fieldY, fieldX) graph.graphAxis.title = "Near Y" graph.graphAxis.title = "Near X" graph.graphPropsGeneral.title = "Test of Flake Property Graph" arcpy.MakeGraph_management(graph_template, graph, out_graph_name) arcpy.SaveGraph_management(out_graph_name, out_graph, "MAINTAIN_ASPECT_RATIO", 600, 375)
How do you insert out_graph into current_MXD?