theList = ['a', 'b', 'c', 'd'] otherList = [1, 2, 3, 4] listLength = len(theList) for x in range(0, listLength): print str(theList), str(otherList)
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] # pick the layer you want to "extract" data from #For each work order: rows = arcpy.SearchCursor(lyr1, "", "", "FID", "FID") for row in rows: name = str(row.getValue('Name')) sqlExp = '"FID" = ' + str(row.getValue('FID')) # Create a clause to select only the current record lyr1.definitionQuery = sqlExp 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
#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")) #ADJUST FILE PATH METHOD field = "voila" MyList = [3, 4, 5, 6, 7] for values in MyList: 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: # Create a clause to select only the current record titleElem.text = str(row.voila) labelElem.text = str(row.Letter) for df in dfs: for lyr in arcpy.mapping.ListLayers(mxd, "voila"): #set the definition query of the poles layer lyr.definitionQuery = whereclause #Export each theme to a temporary PDF and append to the final PDFprint "export to pdf" tmpPdf = os.path.join(output, str(row.voila) + ".pdf") #ADJUST FILE PATH METHOD arcpy.mapping.ExportToPDF(mxd, tmpPdf, resolution=240) finalPdf.appendPages(tmpPdf) print "All done." del mxd
import arcpy, os shape = r"K:\Working\Alex_Gole\cult.shp" output = r"K:\Working\Alex_Gole\test\" output = "in_memory\" ## to save temp pdf "in memory" to save filespace and speed. Not sure if this will work for the pdf tool. If not, delete unless you need individual PDF's after appending. finalPdf = arcpy.mapping.PDFDocumentCreate(os.path.join(output, "All.pdf")) #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: # whereclause = '"voila"' "= " + str(values) ### 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] ## Have to adjust if you need the query, etc. on more than one dataframe titleElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT","Figure name")[0] ## Assuming you have created a text element in mxd with Element Name = "Figure name" labelElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT","Label")[0] ## Assuming you have created a text element in mxd with Element Name = "Label" lyr1 = arcpy.mapping.ListLayers(mxd, "poles", dfs)[0] ## Have to adjust if you need the query, etc. on more than one dataframe sCur = arcpy.SearchCursor(shape) for row in sCur: voila_var = str(row.getValue(voila)) letter_var = str(row.getValue(Letter)) fid_var = row.getValue(FID) whereclause = '"voila" = \'' + voila_var + "' ## creates PDF for each macthing FC #whereclause = '"FID" = ' + str(fid_var) ## comment out other whereclause and use this one to create PDF for EACH FC, regardless of voila value. titleElem.text = voila_var labelElem.text = letter_var lyr1.definitionQuery = whereclause ## This actually puts defquery on the poles layer using the cult.shp values?? mxd.save() ## need to save chages to mxd before you export to PDF or changes won't be represeted. #Export each theme to a temporary PDF and append to the final PDFprint "export to pdf" tmpPdf = os.path.join(output, voila_var + ".pdf") #ADJUST FILE PATH METHOD arcpy.mapping.ExportToPDF(mxd, tmpPdf, resolution=240) finalPdf.appendPages(tmpPdf) print "All done." del mxd
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.