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:
and
else:
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?