-1

I've got about 70 MXDs that need the top data frame name (there are multiple data frames within the MXD, I need to adjust the top data frame) changed/replaced.

This is a task that may need to be performed again and again so I want to develop a script that will change the data frame name. For example, change 'Data' to 'Layers'.

closed as off-topic by PolyGeo Sep 6 '16 at 23:34

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    For coding questions please post code that you have tried and note where you are stuck or any errors. This forum discourages against "do it for me questions". – artwork21 Sep 6 '16 at 23:20
5

Using info from DataFrame - to change data frame 'Data' to 'Layers':

import arcpy
arcpy.env.workspace = r"c:\temp"
for mxd_file in arcpy.ListFiles(*.mxd):
    mxd = arcpy.mapping.MapDocument(mxd_file)
    for df in arcpy.mapping.ListDataFrames(mxd):
        if df.name == 'Data':
            df.name = 'Layers'
    mxd.save()
    del mxd

Or to modify the name of the top data frame, no matter it's current name:

import arcpy
arcpy.env.workspace = r"c:\temp"
for mxd_file in arcpy.ListFiles(*.mxd):
    mxd = arcpy.mapping.MapDocument(mxd_file)
    df = arcpy.mapping.ListDataFrames(mxd)[0]
    df.name = 'Layers'
    mxd.save()
    del mxd
  • Is there a way to point the script to a folder of MXDs? – Christopher Harrod Sep 6 '16 at 20:57
  • @ChristopherHarrod updated to loop through MXDs in a folder – Midavalo Sep 6 '16 at 21:01

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