1

I have a template that contains two individual data frames amongst other elements. I am using a python script to populate this template, and for one of the dataframes I am using a json string to populate it with a map using the following code:

# Get the requested map document
templateMxd = os.path.join(templatePath, Layout_Template + '.mxd')

# Convert the WebMap to a map document
result = arcpy.mapping.ConvertWebMapToMapDocument(Web_Map_as_JSON, templateMxd)
mxd = result.mapDocument   

#Get Titleblock Elements
# Note: ConvertWebMapToMapDocument renames the active dataframe in the template_mxd to "Webmap"
DataFrame = arcpy.mapping.ListDataFrames(mxd, 'Webmap')[0]

#get Scale
Scale = int(arcpy.GetParameterAsText(2))
DataFrame.scale = Scale

Now I need to populate the second dataframe with the same data as in the first, however I am having issues. The conversion process from json string to map document renames the active dataframe and saves the result within this dataframe. However I cannot set two dataframes as active at the same time. I have also tried to replicate the code but using the second dataframe name instead of the first however the second dataframe is still remaining blank.

Does anyone have any ideas how you can have two dataframes within the same template both containing the same map document populated using a python script for arcmap?

2 Answers 2

1

arcpy.ListDataFrames(mxd) returns a list of dataframes. If you don't specifiy the second parameter with a string, you will get a list of all the dataframes available in the MXD. If you do populate the second paramter, it will only return frames that meet the wildcard criteria.

So the code would look something similar to this for two dataframes:

dataframe = arcpy.ListDataFrames(mxd)
Scale = int(arcpy.GetParameterAsText(2))

frame1 = dataframe[0]
frame1.scale = Scale

frame2 = dataframe[1]
frame2.scale = Scale
1
  • Thanks for your reply. However my issue isn't with obtaining the dataframe, it's with populating both dataframes with the same map document. No matter what I try one of them always seems to be coming back empty
    – Maeglin77
    Commented Jan 30, 2017 at 7:12
0

once i faced this problem, what i did is i listed out all layers in df1 and added those layers in df2

result = arcpy.mapping.ConvertWebMapToMapDocument(Web_Map_as_JSON,Layout_Template)
mxd = result.mapDocument
mapDocument = arcpy.mapping.MapDocument(templatePath2)
layers = arcpy.mapping.ListLayers(mxd)

dfs = arcpy.mapping.ListDataFrames(mxd)

for df in dfs : 
     arcpy.AddMessage('df name is  {0}'.format(df.name))
     if df.name == 'New Data Frame':
     for lyr in layers:
          arcpy.mapping.AddLayer(df,  lyr)
          arcpy.AddMessage('added {0}'.format(lyr))

     df.zoomToSelectedFeatures()

here New Data Frame is the name of second data frame. first dataframe would be Webmap.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.