<?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: Create MXD for each FC row in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/create-mxd-for-each-fc-row/m-p/557620#M43587</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Why would you want 125 MXD files in the first place?? Surely the point of Python scripting is that you manipulate one MXD to avoid the proliferation of MXD files. Out of curiosity I have just done a count on my system and I only have 222 MXD files after 10 years of ArcGIS processing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The &lt;/SPAN&gt;&lt;STRONG&gt;mapping&lt;/STRONG&gt;&lt;SPAN&gt; module helps a lot with reducing the number of MXDs required, but you can also use templates, layer files, styles to reduce the number.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 28 May 2013 09:35:28 GMT</pubDate>
    <dc:creator>KimOllivier</dc:creator>
    <dc:date>2013-05-28T09:35:28Z</dc:date>
    <item>
      <title>Create MXD for each FC row</title>
      <link>https://community.esri.com/t5/python-questions/create-mxd-for-each-fc-row/m-p/557618#M43585</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi all,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have FC with 125 rows, and I would like to make a separate MXD for each single attribute I have got . In this case I will be using the FID for my loop. My scripts is not working as I wish. Do anyone have an idea how to automate this process? Thank you&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Attach is my script:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy, os&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy import env&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#Overwrite features&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.overwriteOutput = True&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;shape = r"K:\Working\Alex_Gole\cult.shp"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;output = r"K:\Working\Alex_Gole\test"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;layer = r"K:\Working\Alex_Gole\letter_lyr_new"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;rows = arcpy.SearchCursor(shape, "", "", "FID", "FID")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd = arcpy.mapping.MapDocument(r"K:\Working\Alex_Gole\Try.mxd")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;inset = arcpy.mapping.ListDataFrames(mxd, "New Data Frame")[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#For each work order:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for row in rows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Create a clause to select only the current record&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; whereclause = '"FID" = ' + str(row.FID)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Create a feature layer from the current row only&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(shape, layer, whereclause)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Create feature class for each point&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures_management(layer, r"K:\Working\Alex_Gole\test\try.shp" + str(row.FID))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; newMxd = "Fig1_" + row.Name + ".mxd"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; pathNewMxd = r'K:\Working\Alex_Gole\test\\' + newMxd&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.path.exists(pathNewMxd):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pass&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #copy template and name file "Fig1_Task_WO_Name_NuPoles"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.saveACopy(r"K:\Working\Alex_Gole\test\\"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; + newMxd)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Saving " + newMxd&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print "All done."&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;del mxd&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 May 2013 00:20:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-mxd-for-each-fc-row/m-p/557618#M43585</guid>
      <dc:creator>AlexGole1</dc:creator>
      <dc:date>2013-05-24T00:20:44Z</dc:date>
    </item>
    <item>
      <title>Re: Create MXD for each FC row</title>
      <link>https://community.esri.com/t5/python-questions/create-mxd-for-each-fc-row/m-p/557619#M43586</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;To start: read the post pinned at the top of the list about how to post readable code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Don't try to do stuff inside your cursor loop.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Use the cursor to create a list of FIDs, close the cursor, and then itterate the list.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If you want to save other field values too, use another list and step theough them in paralel &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;using the list index&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;theList = ['a', 'b', 'c', 'd']
otherList = [1, 2, 3, 4]
listLength = len(theList)
for x in range(0, listLength):
&amp;nbsp;&amp;nbsp;&amp;nbsp; print str(theList&lt;X&gt;), str(otherList&lt;X&gt;)&lt;/X&gt;&lt;/X&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;or using a dictionary keyed to the FID, and itterate the dictionary keys list.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try setting the definition query on the layer(s) you already have in the data frame (UpdateLayer)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;instead of making new layers.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;In any event, although you (try to) make layers in your script, &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't see where you add them to the mxd, symbolize them, or remove them when you are done with them.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:04:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-mxd-for-each-fc-row/m-p/557619#M43586</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2021-12-12T00:04:31Z</dc:date>
    </item>
    <item>
      <title>Re: Create MXD for each FC row</title>
      <link>https://community.esri.com/t5/python-questions/create-mxd-for-each-fc-row/m-p/557620#M43587</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Why would you want 125 MXD files in the first place?? Surely the point of Python scripting is that you manipulate one MXD to avoid the proliferation of MXD files. Out of curiosity I have just done a count on my system and I only have 222 MXD files after 10 years of ArcGIS processing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The &lt;/SPAN&gt;&lt;STRONG&gt;mapping&lt;/STRONG&gt;&lt;SPAN&gt; module helps a lot with reducing the number of MXDs required, but you can also use templates, layer files, styles to reduce the number.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 May 2013 09:35:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-mxd-for-each-fc-row/m-p/557620#M43587</guid>
      <dc:creator>KimOllivier</dc:creator>
      <dc:date>2013-05-28T09:35:28Z</dc:date>
    </item>
    <item>
      <title>Re: Create MXD for each FC row</title>
      <link>https://community.esri.com/t5/python-questions/create-mxd-for-each-fc-row/m-p/557621#M43588</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The only reason I could picture that many mxds would be something that could be solved with Data Driven Pages.&amp;nbsp; I use a python script to change queries on an index layer and generate maps based on that.&amp;nbsp; It could be worth some investigation to see if it solves what you're really trying to accomplish.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 May 2013 10:21:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-mxd-for-each-fc-row/m-p/557621#M43588</guid>
      <dc:creator>TimDine</dc:creator>
      <dc:date>2013-05-28T10:21:50Z</dc:date>
    </item>
    <item>
      <title>Re: Create MXD for each FC row</title>
      <link>https://community.esri.com/t5/python-questions/create-mxd-for-each-fc-row/m-p/557622#M43589</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Not sure why you would want a separate mxd, but do you also want to duplicate the data for each one as well?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Why not just put a definition query on the mxd to match the FID that you want, zoom to the displayed features, then save as a new mxd.&amp;nbsp; Then, change the definition query to the next one, zoom to extent, then save as new mxd.&amp;nbsp; This will give you a map document&amp;nbsp; for each of your 125 features, but will utilize the one, already existing data set without having to make a copy.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;something like this should do it:&amp;nbsp; BTW row.name should be row.getValue('Name') - part of why yours wasn't working.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy, os
from arcpy import env
#Overwrite features
arcpy.env.overwriteOutput = True

shape = r"K:\Working\Alex_Gole\cult.shp"
output = r"K:\Working\Alex_Gole\test"
layer = r"K:\Working\Alex_Gole\letter_lyr_new"
mxd = arcpy.mapping.MapDocument(r"K:\Working\Alex_Gole\Try.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
inset = arcpy.mapping.ListDataFrames(mxd, "New Data Frame")[0]


lyr1 = arcpy.mapping.ListLayers(mxd, "cult", df)[0]&amp;nbsp; # pick the layer you want to "extract" data from


#For each work order:
rows = arcpy.SearchCursor(lyr1, "", "", "FID", "FID")
for row in rows:
&amp;nbsp;&amp;nbsp; name = str(row.getValue('Name'))
&amp;nbsp;&amp;nbsp; sqlExp = '"FID" = ' + str(row.getValue('FID'))&amp;nbsp;&amp;nbsp;&amp;nbsp; # Create a clause to select only the current record
&amp;nbsp;&amp;nbsp; lyr1.definitionQuery = sqlExp
&amp;nbsp;&amp;nbsp; df.extent = lyr1.getSelectedExtent(True)


newMxd = "Fig1_" + name
mxd.saveACopy(r"K:\Working\Alex_Gole\test\\" + newMxd + ".mxd")

print "Saving ", newMxd + ".mxd"

print "All done."

del mxd &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a script that is similar, but instead of saving as a new mxd each time (especially since I have over 8000 records), I just &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.mapping.ExportToJPEG(mxd, outfile, resolution=266)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and export to a jpeg file, and move on to the next FID since this is the final output desired anyway.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:04:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-mxd-for-each-fc-row/m-p/557622#M43589</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2021-12-12T00:04:34Z</dc:date>
    </item>
    <item>
      <title>Re: Create MXD for each FC row</title>
      <link>https://community.esri.com/t5/python-questions/create-mxd-for-each-fc-row/m-p/557623#M43590</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;First of all thank you, your script helped me a lot figure out how to iterate a query.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Now, I know a little bit more about the project.&amp;nbsp; The goal is actually to query through a species_ID and export MXD to PDF.The problem is that Species_ID holds multiple values. For instance query: species_ID = 1, 150 records will be returned. It not a row by row query unfortunately. I am also trying to update the title and legend label name for each query. I have used ArcGIS 10.1 to access a list of species_ID. However, I am not familiar at all with this new search cursor, I would not know .&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Alex&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
#Creates draft MXDs for each 1 pole work order.
import arcpy, os
from arcpy import env
#enable overwrite 
arcpy.env.overwriteOutput = True

###
###Cycles through 1 pole work orders and creates MXDs
###
shape = r"K:\Working\Alex_Gole\cult.shp"
output = r"K:\Working\Alex_Gole\test"
finalPdf = arcpy.mapping.PDFDocumentCreate(os.path.join(output, "All.pdf"))&amp;nbsp;&amp;nbsp; #ADJUST FILE PATH METHOD
field = "voila"
MyList = [3, 4, 5, 6, 7]
for values in MyList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; whereclause = '"voila"' "= " + str(values)
rows = arcpy.SearchCursor(shape, "", "", "voila; Letter")
mxd = arcpy.mapping.MapDocument(r"K:\Working\Alex_Gole\Try_new.mxd")
dfs = arcpy.mapping.ListDataFrames(mxd)[0]
titleElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT","Figure name")[0]
labelElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT","Label")[0]
#change definition querry of poles to match work order
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Create a clause to select only the current record
&amp;nbsp;&amp;nbsp;&amp;nbsp; titleElem.text = str(row.voila)
&amp;nbsp;&amp;nbsp;&amp;nbsp; labelElem.text = str(row.Letter)
&amp;nbsp;&amp;nbsp;&amp;nbsp; for df in dfs:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in arcpy.mapping.ListLayers(mxd, "voila"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #set the definition query of the poles layer
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.definitionQuery = whereclause
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Export each theme to a temporary PDF and append to the final PDFprint "export to pdf"
&amp;nbsp;&amp;nbsp;&amp;nbsp; tmpPdf = os.path.join(output, str(row.voila) + ".pdf")&amp;nbsp; #ADJUST FILE PATH METHOD
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportToPDF(mxd, tmpPdf, resolution=240)
&amp;nbsp;&amp;nbsp;&amp;nbsp; finalPdf.appendPages(tmpPdf)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
print "All done."

del mxd
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:04:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-mxd-for-each-fc-row/m-p/557623#M43590</guid>
      <dc:creator>AlexGole1</dc:creator>
      <dc:date>2021-12-12T00:04:37Z</dc:date>
    </item>
    <item>
      <title>Re: Create MXD for each FC row</title>
      <link>https://community.esri.com/t5/python-questions/create-mxd-for-each-fc-row/m-p/557624#M43591</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Alex,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Could use a little more clarification here.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, first of all, are you saying that you want one pdf exported for each FC in your layer or one for each species_ID?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;IOW, for species_ID = 1, it returns 150 records. Do you want one pdf created that shows all 150 features in the extent, or do you actually want 150 pdf documents, one for each of the species_ID=1 features?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(based on last repsonse, I assume you really don't need separate mxd's, just as long as you have separate PDF's ?)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, need to clarify if you are searching/def query on the voila layer or the poles layer as this code applies it to the cult.shp layer???&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;need to iterate through the layer you are actually applying query to. As is, will set the definitionQuery on a layer "poles" in DF "Layers" to the value of "voila" from the cult.shp layer attribute table. I normally SearchCursor the same FC I'm applying the definition query to, that way there is always a "match".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os

shape = r"K:\Working\Alex_Gole\cult.shp"
output = r"K:\Working\Alex_Gole\test\"
output = "in_memory\"&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ## to save temp pdf "in memory" to save filespace and speed.&amp;nbsp; Not sure if this will work for the pdf tool.&amp;nbsp; If not, delete unless you need individual PDF's after appending.
finalPdf = arcpy.mapping.PDFDocumentCreate(os.path.join(output, "All.pdf"))&amp;nbsp;&amp;nbsp; #ADJUST FILE PATH METHOD
mxd = arcpy.mapping.MapDocument(r"K:\Working\Alex_Gole\Try_new.mxd")


#MyList = [3, 4, 5, 6, 7]
#for values in MyList:
#&amp;nbsp;&amp;nbsp;&amp;nbsp; whereclause = '"voila"' "= " + str(values)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ###&amp;nbsp; this is actually setting your whereclause = "voila" = 7 as it is the last in your list, and there is nothing else to "do" here...

dfs = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ## Have to adjust if you need the query, etc. on more than one dataframe
titleElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT","Figure name")[0]&amp;nbsp; ##&amp;nbsp; Assuming you have created a text element in mxd with Element Name = "Figure name"
labelElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT","Label")[0]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ##&amp;nbsp; Assuming you have created a text element in mxd with Element Name = "Label"
lyr1 = arcpy.mapping.ListLayers(mxd, "poles", dfs)[0]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ## Have to adjust if you need the query, etc. on more than one dataframe


sCur = arcpy.SearchCursor(shape)

for row in sCur:
&amp;nbsp;&amp;nbsp;&amp;nbsp; voila_var = str(row.getValue(voila)) 
&amp;nbsp;&amp;nbsp;&amp;nbsp; letter_var = str(row.getValue(Letter)) 
&amp;nbsp;&amp;nbsp;&amp;nbsp; fid_var = row.getValue(FID)
&amp;nbsp;&amp;nbsp;&amp;nbsp; whereclause = '"voila" = \'' + voila_var + "'&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ## creates PDF for each macthing FC
&amp;nbsp;&amp;nbsp;&amp;nbsp; #whereclause = '"FID" = ' + str(fid_var)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ## comment out other whereclause and use this one to create PDF for EACH FC, regardless of voila value.
&amp;nbsp;&amp;nbsp;&amp;nbsp; titleElem.text = voila_var&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; labelElem.text = letter_var
&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr1.definitionQuery = whereclause&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ## This actually puts defquery on the poles layer using the cult.shp values??
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.save()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ## need to save chages to mxd before you export to PDF or changes won't be represeted.
 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Export each theme to a temporary PDF and append to the final PDFprint "export to pdf"
&amp;nbsp;&amp;nbsp;&amp;nbsp; tmpPdf = os.path.join(output, voila_var + ".pdf")&amp;nbsp; #ADJUST FILE PATH METHOD
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportToPDF(mxd, tmpPdf, resolution=240)
&amp;nbsp;&amp;nbsp;&amp;nbsp; finalPdf.appendPages(tmpPdf)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
print "All done."

del mxd&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If this workflow doesn't get you on the right track, let us know the other specifics.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Have not tested this specifically, but is right our of one of my working scripts, so the basic structure should work. Might have to adjust variable names, syntax, etc.,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:37:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-mxd-for-each-fc-row/m-p/557624#M43591</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2021-12-12T16:37:41Z</dc:date>
    </item>
  </channel>
</rss>

