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.
1 Answer 1
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()
-
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– Dave Miller2019年04月26日 13:57:58 +00:00Commented Apr 26, 2019 at 13:57
-
Add singel quotes around the one in sql line:
'{1}'
Bera– Bera2019年04月26日 14:01:26 +00:00Commented Apr 26, 2019 at 14:01 -
1Excellent - this now works a treat. Thanks for the help!Dave Miller– Dave Miller2019年04月26日 15:13:43 +00:00Commented Apr 26, 2019 at 15:13
Explore related questions
See similar questions with these tags.