import arcpy, os myPath = r"K:\Working\Alex_Gole\Try\\" arcpy.env.workspace = myPath myMap = arcpy.mapping.MapDocument(myPath + "MyMap.mxd") layer = arcpy.mapping.ListLayers(myMap) vislayer = layer.isGroupLayer df = arcpy.mapping.ListDataFrames(myMap)[0] # Clear visibility of all layers except for the community areas layer for lyr in vislayer: print "Turning on Layer " + lyr.name lyr.visible = True else: print "Turning off layer " + lyr.name lyr.visible = False #Export to PDF print "exporting map" arcpy.mapping.ExportToPDF(myMap, myPath + str(vislayer.name) + ".pdf")
import arcpy, os, sys path = os.path.dirname(sys.argv[0]) mxd = arcpy.mapping.MapDocument(path + r"/MyMap.mxd") outputPath = r"K:\Working\Alex_Gole\Try" mapLyr = arcpy.mapping.ListLayers(mxd)[0] for lyr in mapLyr: if lyr.isGroupLayer: print "Turning on group Layer " + lyr.name lyr.visible = True else: lyr.visible = False if os.path.exists(path + "layers.pdf"): os.remove(path + "layers.pdf") arcpy.mapping.ExportToPDF(mxd, os.path.join(outputPath, lyr.name + "layers.pdf"))
import arcpy, os myPath = r"K:\Working\Alex_Gole\Try\\" arcpy.env.workspace = myPath myMap = arcpy.mapping.MapDocument(myPath + "MyMap.mxd") layer = arcpy.mapping.ListLayers(myMap) df = arcpy.mapping.ListDataFrames(myMap)[0] # Clear visibility of all layers except for the community areas layer for lyr in layer: if lyr.isGroupLayer: print "Turning on Layer " + lyr.name lyr.visible = True else: print "Turning off layer " + lyr.name lyr.visible = False #Export to PDF print "exporting map" arcpy.mapping.ExportToPDF(myMap, myPath + str(lyr.name) + ".pdf")
Can you try removing the if lyr.isGroupLayer:andelse:Then just try printing the lyr.name property to ensure that you are indeed looping through the layers.
Are you looking to export to pdf while looping thru each layer or are you just trying to do an export to pdf for the group layer?
Seems to me that you should put the export to pdf statement in the GroupLayer true portion of the if else clause. I would think it is currently exporting every layer out to a pdf since the export to pdf statement is outside the if else clause but within the for loop.
import arcpy, os, sys myPath = os.path.dirname(sys.argv[0]) myMap = arcpy.mapping.MapDocument(myPath + r"/MyMap2.mxd") layer = arcpy.mapping.ListLayers(myMap, "Map_Elem_Table_v2")[0] rows = arcpy.SearchCursor(layer) # Legend Items fignumElem = arcpy.mapping.ListLayoutElements(myMap, "TEXT_ELEMENT","FigNumber")[0] titleElem = arcpy.mapping.ListLayoutElements(myMap, "TEXT_ELEMENT","FigTitle")[0] sourceElem = arcpy.mapping.ListLayoutElements(myMap, "TEXT_ELEMENT","FigSource")[0] #create a cursor to access values from attribute table for row in rows: fignumElem.text = str(row.FigNumber) titleElem.text = unicode(row.FigTitle) sourceElem.text = str(row.FigSource) # Loop through each Group layer and export to PDF for lyr in layer: if lyr.isGroupLayer: print "Turning on Layer " + lyr.name lyr.visible = True print "exporting map" arcpy.mapping.ExportToPDF(myMap, myPath + str(lyr.name) + ".pdf") else: print "Turning off layer " + lyr.name lyr.visible = False
Is Map_Elem_Table_v2 a standalone table or the table associated with the feature class?If it is a standalone table, I think you need to use the ListTables function to get to the tabular data that you are looking for.
tables = arcpy.ListTables() # Legend Items fignumElem = arcpy.mapping.ListLayoutElements(myMap, "TEXT_ELEMENT","FigNumber")[0] titleElem = arcpy.mapping.ListLayoutElements(myMap, "TEXT_ELEMENT","FigTitle")[0] sourceElem = arcpy.mapping.ListLayoutElements(myMap, "TEXT_ELEMENT","FigSource")[0] #create a cursor to access values from attribute table for table in tables: fignumElem.text = str(row.FigNumber) titleElem.text = unicode(row.FigTitle) sourceElem.text = str(row.FigSource)
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.