2

I'm designing a workflow involving 1km grid cells which are referenced by data driven pages. In it the user will use the data driven pages toolbar to skip to the next cell in the index layer and perform a manual interpretation task for that record. This will simply involve clicking on buttons set up in a custom toolbar. So far so good.

What I'd like to do is for ArcMap to automatically select the record in the index layer to which the data driven pages value relates. I have a hunch that this is possible but I can't find a way to make it happen.

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Apr 26, 2019 at 7:53

1 Answer 1

2

It is possible using arcpy mapping DataDrivenPages. You could put something similiar in your custom button:

import arcpy
def nextpage_and_select():
 mxd = arcpy.mapping.MapDocument("CURRENT")
 ddp = mxd.dataDrivenPages
 layer = ddp.indexLayer.name
 fieldname = ddp.pageNameField.name
 if ddp.currentPageID>1:
 ddp.currentPageID += 1
 arcpy.RefreshActiveView()
 current_value = ddp.pageRow.getValue(fieldname)
 sql = "{0}={1}".format(arcpy.AddFieldDelimiters(datasource=layer, field=fieldname), current_value)
 arcpy.SelectLayerByAttribute_management(in_layer_or_view=layer, 
 where_clause=sql)

Call function:

nextpage_and_select()

enter image description here

answered Apr 26, 2019 at 8:16
3
  • Thanks for coming back to me on this. I think it's pretty close to what is needed. The index field is a text string rather (e.g. "NJ3011") than a numeric value. I think this may be the issue with using the current code. It needs to be modified but I can't see how. Any ideas? Commented Apr 26, 2019 at 13:57
  • Add singel quotes around the one in sql line: '{1}' Commented Apr 26, 2019 at 14:01
  • 1
    Excellent - this now works a treat. Thanks for the help! Commented Apr 26, 2019 at 15:13

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.