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.

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

  • 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? – Dave Miller Apr 26 at 13:57
  • Add singel quotes around the one in sql line: '{1}' – BERA Apr 26 at 14:01
  • 1
    Excellent - this now works a treat. Thanks for the help! – Dave Miller Apr 26 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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