1

Is there a way to dynamically pull in a new index layer for a data driven page in ArcMap?

Scenario: I have an MXD which will be my template. I am trying to update the index layer dynamically in Python. I want to switch out my "dummy" index layer with the layer that gets fed to the MXD by the user/my Python script.

1

1 Answer 1

0

Here's snippets from my previous endeavour. My template mxd contained a templated DDP feature class/layer. The new DDP contained the same schema. Look up the ESRI docs for any of the methods used below.

import arcpy
import arcpy.mapping as m
mxd = m.MapDocument("mxd_path")
## make sure your saved mxd already had ddp enabled
ddp = mxd.dataDrivenPages
## get the ddp layer
ddp_lyr = m.ListLayers(mxd, "ddp_lyr_name", "df_name")[0]
## replace the datasource with another feature class
ddp_lyr.replaceDataSource("path_to_workspace", "FILEGDB_WORKSPACE", "new_ddp_fc_name")
ddp.refresh()
## to save the mxd with a the updated ddp layer
## or use mxd.saveACopy() to keep your template and save another mxd. 
mxd.save()

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.