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.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked May 4, 2021 at 22:21
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()
answered May 25, 2021 at 8:01

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.