I am trying to find a way to update the index layer for data driven pages through arcpy. I understand that to access DDP from arcpy.mapping you need to be referencing a MXD that has DDP enabled. My problem is that I am trying to create DDP for a feature class I just created from the XML to Geodatabase import tool and use that as my index layer instead of the scratch layer I created to enable DDP. The MXD contains a layout I would ultimately like to use when exporting my DDP. Here is my code so far.
# Import arcpy moduleimport arcpy, osfrom arcpy import envenv.overwriteOutput = Trueenv.workspace = r"C:\Users\spadgett\Desktop\ArcScrap\Tyler_TEST.gdb"# Script parameterxml = arcpy.GetParameterAsText(0)# Hardcoded GDB for storing xmlTyler_TEST_gdb = "C:\\Users\\spadgett\\Desktop\\ArcScrap\\Tyler_TEST.gdb"# execute xml to geodatabase toolarcpy.AddMessage("Executing XML to Geodatabase")arcpy.ImportXMLWorkspaceDocument_management(Tyler_TEST_gdb, xml, "DATA", "")#create feature layer for pointsFCpoints = "Control_Point_Name"arcpy.AddField_management(FCpoints, "SCALE", "SHORT")arcpy.CalculateField_management(FCpoints, "SCALE", "1200", "PYTHON")arcpy.AddMessage("Points feature class added with SCALE field")arcpy.MakeFeatureLayer_management(FCpoints,"Points2")# Set environment and MXDmxd = arcpy.mapping.MapDocument(r"C:\Users\spadgett\Desktop\ArcScrap\Tyler Sample\Tyler_Test.mxd")df = arcpy.mapping.ListDataFrames(mxd)[0]layer = arcpy.mapping.Layer("Points2")arcpy.mapping.AddLayer(df, layer, "TOP")RefPoints = r"C:\Users\spadgett\Desktop\ArcScrap\LYR\Points.lyr"updateLayer = arcpy.mapping.ListLayers(mxd)[0]arcpy.ApplySymbologyFromLayer_management (updateLayer, RefPoints)mxd.save()updateLayerOld = arcpy.mapping.ListLayers(mxd)[1]arcpy.mapping.UpdateLayer(df, updateLayerOld, updateLayer, False)mxd.dataDrivenPages.refresh()mxd.save()#Create JPG of DDP for Points name##mxd = arcpy.mapping.MapDocument("CURRENT")for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1): mxd.dataDrivenPages.currentPageID = pageNum pageName = mxd.dataDrivenPages.pageRow.Name arcpy.mapping.ExportToJPEG(mxd, r"C:\Users\spadgett\Desktop\ArcScrap\Tyler Sample\Images\AGM_" + str(pageName) + ".jpg")Running this code ends up with an error at the UpdateLayer line. Switching the boolean to True just changes the symbology, just as the help document says. Any ideas? Thanks!
Edit: Error is
Traceback (most recent call last): File "C:\Users\spadgett\Desktop\ArcScrap\Tyler Sample\python\AGM_Report.py", line 59, in arcpy.mapping.UpdateLayer(df, updateLayerOld, updateLayer, False) File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\utils.py", line 181, in fn_ return fn(*args, **kw) File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\mapping.py", line 1876, in UpdateLayer tc.ReplaceLayer(tl, rl)ValueError: DataFrameObject: Unexpected error
أكثر...
# Import arcpy moduleimport arcpy, osfrom arcpy import envenv.overwriteOutput = Trueenv.workspace = r"C:\Users\spadgett\Desktop\ArcScrap\Tyler_TEST.gdb"# Script parameterxml = arcpy.GetParameterAsText(0)# Hardcoded GDB for storing xmlTyler_TEST_gdb = "C:\\Users\\spadgett\\Desktop\\ArcScrap\\Tyler_TEST.gdb"# execute xml to geodatabase toolarcpy.AddMessage("Executing XML to Geodatabase")arcpy.ImportXMLWorkspaceDocument_management(Tyler_TEST_gdb, xml, "DATA", "")#create feature layer for pointsFCpoints = "Control_Point_Name"arcpy.AddField_management(FCpoints, "SCALE", "SHORT")arcpy.CalculateField_management(FCpoints, "SCALE", "1200", "PYTHON")arcpy.AddMessage("Points feature class added with SCALE field")arcpy.MakeFeatureLayer_management(FCpoints,"Points2")# Set environment and MXDmxd = arcpy.mapping.MapDocument(r"C:\Users\spadgett\Desktop\ArcScrap\Tyler Sample\Tyler_Test.mxd")df = arcpy.mapping.ListDataFrames(mxd)[0]layer = arcpy.mapping.Layer("Points2")arcpy.mapping.AddLayer(df, layer, "TOP")RefPoints = r"C:\Users\spadgett\Desktop\ArcScrap\LYR\Points.lyr"updateLayer = arcpy.mapping.ListLayers(mxd)[0]arcpy.ApplySymbologyFromLayer_management (updateLayer, RefPoints)mxd.save()updateLayerOld = arcpy.mapping.ListLayers(mxd)[1]arcpy.mapping.UpdateLayer(df, updateLayerOld, updateLayer, False)mxd.dataDrivenPages.refresh()mxd.save()#Create JPG of DDP for Points name##mxd = arcpy.mapping.MapDocument("CURRENT")for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1): mxd.dataDrivenPages.currentPageID = pageNum pageName = mxd.dataDrivenPages.pageRow.Name arcpy.mapping.ExportToJPEG(mxd, r"C:\Users\spadgett\Desktop\ArcScrap\Tyler Sample\Images\AGM_" + str(pageName) + ".jpg")Running this code ends up with an error at the UpdateLayer line. Switching the boolean to True just changes the symbology, just as the help document says. Any ideas? Thanks!
Edit: Error is
Traceback (most recent call last): File "C:\Users\spadgett\Desktop\ArcScrap\Tyler Sample\python\AGM_Report.py", line 59, in arcpy.mapping.UpdateLayer(df, updateLayerOld, updateLayer, False) File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\utils.py", line 181, in fn_ return fn(*args, **kw) File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\mapping.py", line 1876, in UpdateLayer tc.ReplaceLayer(tl, rl)ValueError: DataFrameObject: Unexpected error
أكثر...