<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Set DDP index layer with python? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/set-ddp-index-layer-with-python/m-p/743604#M57478</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;An interesting problem, have you tried something like deleting features in a 'dummy' or existing index layer for which DDP are already set up, then appending the new features corresponding to the new extent/size etc.&amp;nbsp; in theory, since you haven't actually changed the internal relationship of the index feature layer in the map and the DDP software, once you 'refill' it with new legitimate features, the output will only need to be refreshed...the export to PDF should be dynamic anyway - how else do pages reflect new page content?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So set up your document DDP enabled mxd with the index and other necessary layers loaded and setup...then I'd run a simple test to see if you can delete an index feature, say, by page number, then append a grid feature (make one up) with that corresponding page number (and any related necessary values for that feature record) and see if you can export the new page by data driven arcpy methods.&amp;nbsp; Fairly simple test I think- in fact, that's a great 'template' example I may experiment with tomorrow.&amp;nbsp; As time permits of course...let me know what results you arrive at, I'd be interested how well this works.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 04 Dec 2012 21:58:31 GMT</pubDate>
    <dc:creator>T__WayneWhitley</dc:creator>
    <dc:date>2012-12-04T21:58:31Z</dc:date>
    <item>
      <title>Set DDP index layer with python?</title>
      <link>https://community.esri.com/t5/python-questions/set-ddp-index-layer-with-python/m-p/743603#M57477</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a set of Data Driven Pages with counties and land cover already made.&amp;nbsp; I am trying to create a tool that will take input of a county name and spawn a new set of DDP at a 4000M per grid square.&amp;nbsp; I have been able to select, clip and&amp;nbsp; create a smaller grid focusing on the area of interest but can not reset the index layer.&amp;nbsp; Is this possible, and if not is there a work around?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Dec 2012 20:31:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/set-ddp-index-layer-with-python/m-p/743603#M57477</guid>
      <dc:creator>TomKearns</dc:creator>
      <dc:date>2012-12-04T20:31:19Z</dc:date>
    </item>
    <item>
      <title>Re: Set DDP index layer with python?</title>
      <link>https://community.esri.com/t5/python-questions/set-ddp-index-layer-with-python/m-p/743604#M57478</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;An interesting problem, have you tried something like deleting features in a 'dummy' or existing index layer for which DDP are already set up, then appending the new features corresponding to the new extent/size etc.&amp;nbsp; in theory, since you haven't actually changed the internal relationship of the index feature layer in the map and the DDP software, once you 'refill' it with new legitimate features, the output will only need to be refreshed...the export to PDF should be dynamic anyway - how else do pages reflect new page content?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So set up your document DDP enabled mxd with the index and other necessary layers loaded and setup...then I'd run a simple test to see if you can delete an index feature, say, by page number, then append a grid feature (make one up) with that corresponding page number (and any related necessary values for that feature record) and see if you can export the new page by data driven arcpy methods.&amp;nbsp; Fairly simple test I think- in fact, that's a great 'template' example I may experiment with tomorrow.&amp;nbsp; As time permits of course...let me know what results you arrive at, I'd be interested how well this works.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Dec 2012 21:58:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/set-ddp-index-layer-with-python/m-p/743604#M57478</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2012-12-04T21:58:31Z</dc:date>
    </item>
    <item>
      <title>Re: Set DDP index layer with python?</title>
      <link>https://community.esri.com/t5/python-questions/set-ddp-index-layer-with-python/m-p/743605#M57479</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you very much for your response.&amp;nbsp; Using part of what you said, I think I got it to work.&amp;nbsp; I just used UpdateLayer to switch out the original Index layer for the grid created in the code.&amp;nbsp; After manually refreshing the DDP it updated perfectly.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Dec 2012 00:16:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/set-ddp-index-layer-with-python/m-p/743605#M57479</guid>
      <dc:creator>TomKearns</dc:creator>
      <dc:date>2012-12-05T00:16:51Z</dc:date>
    </item>
    <item>
      <title>Re: Set DDP index layer with python?</title>
      <link>https://community.esri.com/t5/python-questions/set-ddp-index-layer-with-python/m-p/743606#M57480</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That's good to know!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Dec 2012 01:39:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/set-ddp-index-layer-with-python/m-p/743606#M57480</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2012-12-05T01:39:31Z</dc:date>
    </item>
    <item>
      <title>Re: Set DDP index layer with python?</title>
      <link>https://community.esri.com/t5/python-questions/set-ddp-index-layer-with-python/m-p/743607#M57481</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Unfortunately after working on the problem some more the fix no longer works.&amp;nbsp; For whatever reason the layer updated as I wanted last night, but when I run the program now it automatically switches to a different layer.&amp;nbsp; I am going to phrase this in another question and post it after&amp;nbsp; I comb through the forums to see if it is already there.&amp;nbsp; Very frustrating that it worked multiple times last night but not today.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Dec 2012 23:37:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/set-ddp-index-layer-with-python/m-p/743607#M57481</guid>
      <dc:creator>TomKearns</dc:creator>
      <dc:date>2012-12-05T23:37:57Z</dc:date>
    </item>
    <item>
      <title>Re: Set DDP index layer with python?</title>
      <link>https://community.esri.com/t5/python-questions/set-ddp-index-layer-with-python/m-p/743608#M57482</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'd like to explore this problem if I get time tomorrow... did you notice the 'fix' stop working after you exited ArcMap or did something else?&amp;nbsp; Also, the index layers you want to use are all from the same schema, i.e. same fields, etc., and nothing changing except the record values?&amp;nbsp; If so, you can test the other idea of 'emptying' (deleting features) in the index and reloading it (appending features).&amp;nbsp; Seems to me that way no internal ArcMap linked functionality would be broken....what worked before should simply be functioning the same way, just using new values.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I noticed the 'updateLayer' documentation stated it was equivalent to a kind of 'remove and replace':&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"UpdateLayer, when not restricted to symbology, is essentially calling the RemoveLayer and AddLayer functions."&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;...which, I don't know, seems to me could 'break' something.&amp;nbsp; If that sound vague, that's because it is....unknown to me until I test it out.&amp;nbsp; Your method may have broken only parts evident later, just don't know.&amp;nbsp; If I find out anything tomorrow I'll post back here.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EDIT:&amp;nbsp; I just thought of something - there may be field value dependencies that exist... but for things like dynamic text, seems like you could simply adjust those if you need to in the layout template.&amp;nbsp; Anyway, something to think about, and if you had to, you could even potentially keep the same records and update the field values (including the geometry) with an update cursor.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Dec 2012 00:05:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/set-ddp-index-layer-with-python/m-p/743608#M57482</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2012-12-06T00:05:22Z</dc:date>
    </item>
    <item>
      <title>Re: Set DDP index layer with python?</title>
      <link>https://community.esri.com/t5/python-questions/set-ddp-index-layer-with-python/m-p/743609#M57483</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Unfortunately I altered major pieces of my overall code and would be unable to trace back to what I had last night that accomplished my goal.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A restatement of my problem would be as follows:&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have an MXD with Data Driven Pages enabled (sorted by county) that has multiple feature classes in it (Land cover, land ownership, road layers...) I am writing a tool that will take the input of a county name and create a new set of DDP based on a grid of Xnumber of meters (will be a constant in the code) showing only that county and export them to a PDF.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Last night I used UpdateLayer to replace the counties layer that the original DDP were sorted by with the grid layer I created within the script.&amp;nbsp; When I refreshed using the DDP toolbar manually it switched the DDP index layer to the grid layer. (Perfect)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Today, after I altered my code, when I refreshed the DDP manually it switched the index to a different layer, one which will not work for organizing the DDP.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The actual UpdateLayer code was updated to reflect a separate mxd, even though it was a copy of the one previously used.&amp;nbsp; I am wondering if&amp;nbsp; it has to do with the order the layers are in the new mxd.&amp;nbsp; If yesterdays version had the grid file in first position it could have automatically slid into the Index layer and worked no matter what I was replacing it with.&amp;nbsp; If I get a chance I will code that layer to the top before I copy it, and then redo the layer update.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Dec 2012 00:23:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/set-ddp-index-layer-with-python/m-p/743609#M57483</guid>
      <dc:creator>TomKearns</dc:creator>
      <dc:date>2012-12-06T00:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: Set DDP index layer with python?</title>
      <link>https://community.esri.com/t5/python-questions/set-ddp-index-layer-with-python/m-p/743610#M57484</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I moved the grid layer above the other (using MoveLayer) before running the UpdateLayer command and achieved the desired result.&amp;nbsp; It is working again for the moment.&amp;nbsp; When I refreshed the DDP from the DDP toolbar and checked the Index layer it had become the grid layer I wanted.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Edit:&amp;nbsp; The dynamic text name updated from the County name to the Grid name.&amp;nbsp; The page number also updated to reflect the proper number of pages in what will be the new mapbook.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Dec 2012 00:37:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/set-ddp-index-layer-with-python/m-p/743610#M57484</guid>
      <dc:creator>TomKearns</dc:creator>
      <dc:date>2012-12-06T00:37:13Z</dc:date>
    </item>
    <item>
      <title>Re: Set DDP index layer with python?</title>
      <link>https://community.esri.com/t5/python-questions/set-ddp-index-layer-with-python/m-p/743611#M57485</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I don't quite understand why a layer would need to be moved... if you are getting a reference to a layer by name, as with:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;updateLayer = arcpy.mapping.ListLayers(mxd, "Rivers", df)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;...then, ListLayers returns a list object filtering for only those layers with the text in the name, "Rivers" (for the above example which is in the webhelp ref for updateLayer documentation).&amp;nbsp; Incidentally, the use of updateLayer in the example is arguably a bad choice because this is just a layer object variable -- the [0] simply extracts the object from the list (hopefully the only object in the list).&amp;nbsp; In other words, it has nothing to do with the order in the map.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is the order of the layer in the map relevant to the setup of the DDP index layer?&amp;nbsp; I don't think so.&amp;nbsp; I think it is a refence by name only, right?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EDIT:&amp;nbsp; Should probably include the 3 lines of code in the sample together:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;updateLayer = arcpy.mapping.ListLayers(mxd, "Rivers", df)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sourceLayer = arcpy.mapping.Layer(r"C:\Project\Data\Rivers.lyr")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.mapping.UpdateLayer(df, updateLayer, sourceLayer, True)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The 1st line I've already discussed; the 2nd line sets a sourceLayer layer object from a lyr file.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Finally the 3rd line uses the UpdateLayer method (or function) to 'switch' layers.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;So, you could use this technique with a lyr library defining county extents, etc., to change the index layer without cluttering your map of 'extra' layers.....theoretically, of course.&amp;nbsp; Hope I am understanding the technique you are trying to emulate here.&amp;nbsp; Good luck!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Dec 2012 00:49:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/set-ddp-index-layer-with-python/m-p/743611#M57485</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2012-12-06T00:49:48Z</dc:date>
    </item>
    <item>
      <title>Re: Set DDP index layer with python?</title>
      <link>https://community.esri.com/t5/python-questions/set-ddp-index-layer-with-python/m-p/743612#M57486</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have replicated the problem by commenting out the first four lines of code.&amp;nbsp; With them in, the Grid layer becomes the Index layer, with them removed the LINN_OrAndWaOwnership layer becomes the Index layer.&amp;nbsp; I used the move command because I will be reordering 10+ layers and wanted to streamline the process.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; layerMoveUp= arcpy.mapping.ListLayers(mxd2, "LINN_grid", df)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; layerMoveDown= arcpy.mapping.ListLayers(mxd2, "LINN_OrAndWaOwnership", df)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; move = arcpy.mapping.MoveLayer(df, layerMoveDown ,layerMoveUp, "BEFORE" )&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; move&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Reset Data Driven Page Index Layer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; indexLayerOut = arcpy.mapping.ListLayers(mxd2, "Counties", df)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; indexLayerIn = arcpy.mapping.ListLayers(mxd2, "LINN_grid", df)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.UpdateLayer(df, indexLayerOut, indexLayerIn, False)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "index updated"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Refresh DDP - Does not work, must be done manually&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I agree that within the DDP toolbar relative placement has nothing to do with what is set as the index layer.&amp;nbsp; I am only about 4 months into my programming so there is a ton I don't understand about the inner workings. I really appreciate your help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Edit:&amp;nbsp; To further confuse things (or shed light, who knows?)&amp;nbsp; after the index layer has been updated I moved the OrWaOwnership layer above the grid layer later in the script. This resulted in the Ownership layer is once again becoming the Index layer.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Dec 2012 01:20:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/set-ddp-index-layer-with-python/m-p/743612#M57486</guid>
      <dc:creator>TomKearns</dc:creator>
      <dc:date>2012-12-06T01:20:07Z</dc:date>
    </item>
    <item>
      <title>Re: Set DDP index layer with python?</title>
      <link>https://community.esri.com/t5/python-questions/set-ddp-index-layer-with-python/m-p/743613#M57487</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Here's an idea, and I'm keeping this very simple if for no other reason I haven't seen the rest of your code to know exactly how you are implementing this - maybe it doesn't matter though.&amp;nbsp; Let me suggest this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1- Suppose you had all grids you needed for your project in a single feature class....i.e. all county grids in a single source layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2- The layer object has a parameter that accepts an expression for a definition query, so if you had your grid sets attributed with a county name, you could use the name in a def query, and pass it to the layer object.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3- Use UpdateLayer to replace the index layer object with the def query layer object.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4- Refresh the map...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think what has happened is somehow the layer references have been mixed up - the wildcard param on ListLayers is based on the Name property of the layer...so with all the layer manipulations I suppose it is possible to have passed in the wrong layer name for the data source.&amp;nbsp; Also, remember ListLayers can certainly return more than one layer- don't think this is your problem, but just have to be a little careful with this, maybe query the description if you have one to check which layer you actually have an object on.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can loop to fetch county names from a list (or I think you said this parameter would be furnished one county at a time?) and form the def query from the fetched county name - I think you should be able to get the index layer object from the map and pass in the def query, then simply execute the UpdateLayer function to 'copy' it to the index layer in the map.&amp;nbsp; Not sure, but you may not even need to execute UpdateLayer if you're setting a property on a direct reference to a layer object in the map.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Of course, this all depends on if the DDP will 'play nice' with this technique.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So then (check my syntax, this is untested):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#make sure only 1 layer in the map is called 'index'- or include logic to verify.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;lyr = arcpy.mapping.ListLayers(mxd, 'index', df)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#test this string for proper syntax-- pass in your county param here.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;lyr.definitionQuery = 'your def query string here'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.RefreshActiveView()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;See the definitionQuery property (a read/write property) here:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Layer (arcpy.mapping)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Desktop » Geoprocessing » ArcPy » Mapping module&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//00s300000008000000"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#//00s300000008000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EDIT:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Ah, here I think (see link below) confirms that you don't need UpdateLayer - see the example at the bottom of this page (although this is in used in conjuction with ListTableViews, i.e. tables in the map instead of feature layers, ListLayers should work the same way.)&amp;nbsp; ...meaning that the returned objects and setting of those object properties should be directly reflected in the map.&amp;nbsp; The 'refresh' wasn't necessary because there are no features to view - it's a table only.&amp;nbsp; Notice the def query string.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//00s300000006000000"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#//00s300000006000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;table = arcpy.mapping.ListTableViews(mxd, "TrafficAccidents", df)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;table.definitionQuery = "[Accidents] &amp;gt; 5"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd.save()&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Dec 2012 02:54:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/set-ddp-index-layer-with-python/m-p/743613#M57487</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2012-12-06T02:54:37Z</dc:date>
    </item>
    <item>
      <title>Re: Set DDP index layer with python?</title>
      <link>https://community.esri.com/t5/python-questions/set-ddp-index-layer-with-python/m-p/743614#M57488</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This may not be conclusive testing to suit all your end purposes, but I wanted to report back here that I ran a simple test today on the index layer of one of my existing DDP mxds and I was able to set the definitionQuery property and successfully refresh the DDP so that other operations such as exporting, printing, etc., recognized the 'new' index (no adding, removing, or updating the index layer was necessary).&amp;nbsp; I imagine you've got enough other layer updates to do than to worry about where your index layer reference went (remember an earlier post I suggested creating a 'master' fc containing all county grids so that you can filter them by county from the layer object perspective using a def query).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's an abbreviated example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
arcpy.env.workspace = r'&amp;lt; your workspace string (mine was a gdb) &amp;gt;'
testdoc = r'&amp;lt; your mxd path &amp;gt;'
 
mxd = arcpy.mapping.MapDocument(testdoc)
df = arcpy.mapping.ListDataFrames(mxd, '&amp;lt; your dataframe where your DDP index resides &amp;gt;')[0]

# set layer object reference to the index page
lyr = arcpy.mapping.ListLayers(mxd, '&amp;lt; your index layer name &amp;gt;', df)[0]

# create the appropriate field delimiters for the query string based on the workspace type
indexPageField = arcpy.AddFieldDelimiters(arcpy.env.workspace, '&amp;lt; your index layer page fieldname &amp;gt;')

# create the query, in this case, filtering for pages less than 6 (pgs 1-5)
qry = indexPageField + ' &amp;lt; 6'

# set the layer objects definition query
lyr.definitionQuery = qry

# finally, refresh the DDP -- this is the critical step which will crash if the query is unacceptable...
mxd.dataDrivenPages.refresh()

# here you can test the DDP by getting the pageCount, printing, exporting, etc...
pgCnt = mxd.dataDrivenPages.pageCount
print pgCnt&amp;nbsp;&amp;nbsp; # based on the query, results in 5 pages

# success!
# try changing the definition query to see if the DDP changes correspondingly
qry = indexPageField + ' &amp;lt; 11'
lyr.definitionQuery = qry
mxd.dataDrivenPages.refresh()
 
pgCnt = mxd.dataDrivenPages.pageCount
print pgCnt&amp;nbsp; # based on the changed query, results in 10 pages
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 07:38:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/set-ddp-index-layer-with-python/m-p/743614#M57488</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2021-12-12T07:38:46Z</dc:date>
    </item>
    <item>
      <title>Re: Set DDP index layer with python?</title>
      <link>https://community.esri.com/t5/python-questions/set-ddp-index-layer-with-python/m-p/743615#M57489</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I did something similar.&amp;nbsp; I built an electrical distribution application that allowed someone to enter in a Feeder ID, it would then query the 100's of 1000's of features that match that ID, then use GridIndexFeature to dynamically build a DDP index grid for those features only, and then export the extents/pages out to a multi-page PDF.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Similar to your scenario, I could not do it all with one MXD.&amp;nbsp; For some reason if I dynamically switch out the DDP index layer data source in the map I run the script against, weird, unexplainable things happened.&amp;nbsp; So I did it with 2 mxds.&amp;nbsp; The first MXD had basic layers that I queried and used to build the dynamic DDP index layer.&amp;nbsp; The second MXD is already DDP enabled and when I call .refresh it works well.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The partial code below shows how I used the two MXDs:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy, os, sys
relpath = os.path.dirname(sys.argv[0])
arcpy.env.overwriteOutput = True

####Stript tool parameters
feederID = arcpy.GetParameterAsText(0)

##Part 1 - Create subset to build features
mxd = arcpy.mapping.MapDocument(relpath + r"\\&lt;STRONG&gt;FeederMap1.mxd&lt;/STRONG&gt;")

##Reference appropriate layers and set definition queries
POCLyr = arcpy.mapping.ListLayers(mxd, "Primary Overhead Conductor")[0]
POCLyr.definitionQuery = "\"FEEDERID\" = '" + feederID + "'" 

# Execute GridIndexFeatures
arcpy.GridIndexFeatures_cartography(relpath + r"/Scratch.gdb/DDPgrid", [POCLyr], "INTERSECTFEATURE", "", "", "10000 feet", "6500 feet")
del mxd, POCLyr, PUCLyr, stationLyr

##Part 2 - Prepare Feeder Map and Export to PDF

mxd2 = arcpy.mapping.MapDocument(relpath + r"\\&lt;STRONG&gt;FeederMap2.mxd")&lt;/STRONG&gt;
#Reference appropriate layers and set definition queries
for lyr in arcpy.mapping.ListLayers(mxd2):
&amp;nbsp; if lyr.name == "Primary Overhead Conductor":
&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.definitionQuery = "\"FEEDERID\" = '" + feederID + "'"
&amp;nbsp;&amp;nbsp;&amp;nbsp; POCLyr = lyr
&amp;nbsp; 
ddp = mxd2.dataDrivenPages
ddp.refresh()

ddp.exportToPDF(relpath + r"\Feeder_" + feederID + ".pdf")
del mxd2&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope this helps,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 07:38:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/set-ddp-index-layer-with-python/m-p/743615#M57489</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2021-12-12T07:38:49Z</dc:date>
    </item>
    <item>
      <title>Re: Set DDP index layer with python?</title>
      <link>https://community.esri.com/t5/python-questions/set-ddp-index-layer-with-python/m-p/743616#M57490</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Interesting workaround, I knew it would work.&amp;nbsp; Thanks for your post, I will likely need this in the future.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I figured 'replacing' completely the index datasource was 'breaking' the DDP functionality and wondered if I should have tested the part where you'd need to restructure the page numbering (or other fields) since those values may need to be dynamically maintained.&amp;nbsp; I haven't confirmed, but I suspect as long as you aren't deleting the index fc or layer, you could go as far as clearing it of features and loading it with new ones.....sort of similar to 'reloading' an SDE fc to circumvent having to re-establish privileges, etc. - maybe that's a weak analogy....&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regardless, I see what you mean, thank you very much for the alternate &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;working&lt;/SPAN&gt;&lt;SPAN&gt; solution!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-Wayne&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Dec 2012 14:03:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/set-ddp-index-layer-with-python/m-p/743616#M57490</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2012-12-07T14:03:00Z</dc:date>
    </item>
    <item>
      <title>Re: Set DDP index layer with python?</title>
      <link>https://community.esri.com/t5/python-questions/set-ddp-index-layer-with-python/m-p/1054450#M61035</link>
      <description>&lt;P&gt;I know I'm several years behind here, but I'm a little confused on the query above. The query is assuming the grids are in the same gdb, etc., and that way you just pull in the appropriate file within the gdb?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My problem is similar- 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 dynamically. Would I use a similar approach as above?&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 22:13:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/set-ddp-index-layer-with-python/m-p/1054450#M61035</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-05-04T22:13:59Z</dc:date>
    </item>
  </channel>
</rss>

