Select to view content in your preferred language

Group layers

2321
14
08-21-2013 01:30 PM
AlexGole1
Emerging Contributor
Is there a script that allows you to cycle through multiple group layers and turn on and off group layers one by one?
Thanks,
Alex
0 Kudos
14 Replies
AlexGole1
Emerging Contributor
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.


You are right. It worked perfectly. Now I dont know if it is easy to do but I am trying to update figure title name and source ffor each PDF using a table. Any idea how to do so?
Thanks,
Alex

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
0 Kudos
MichaelVolz
Esteemed Contributor
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.
0 Kudos
AlexGole1
Emerging Contributor
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.


It is a GDB standalone table. How would I point (link) to this table in my script?

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)
    
0 Kudos
MichaelVolz
Esteemed Contributor
if it is the only standalone table, I think you could access it with index 0.

if there is more than 1 table, then use an if then statement to trap it by table.name and then get to the specific field you are looking for.
0 Kudos
AlexGole1
Emerging Contributor
Sorry, I am using a fc. for the legend fig name and source.
0 Kudos