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()

Your Answer

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

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