AnsweredAssumed Answered

How to combine loops or reuse variables

Question asked by jeff.thomasilm on Apr 21, 2020
Latest reply on Apr 22, 2020 by jeff.thomasilm

I have a project with multiple layouts and corresponding maps (1-to-1). The maps/layouts are very similar (to get around Pro's inability to set layer visibility per view) and I want to automate setting up the common layers in each map/layout. It's two basic steps: 1) adjust the def query on one of two layer and 2) center the map frame on the queried feature. I've created a loop that successfully changes the def query on all maps:

maps = proj.listMaps()
for m in maps:
    zhLyr = m.listLayers("Zoning History")[0]
    suLyr = m.listLayers("Special Use Permit")[0]
    if caseType == "C" or caseType == "Z":
        zhLyr.definitionQuery = "CaseNumber = '" + case + "'"
        zhLyr.visible = True
        suLyr.visible = False
    elif caseType == "S":
        suLyr.definitionQuery = "CaseNumber = '" + case + "'"
        suLyr.visible = True
        zhLyr.visible = False

I conceptually know how to loop through the layouts and center them on the feature:

layouts = proj.listLayouts()      
for l in layouts:
    mf = l.listElements("MAPFRAME_ELEMENT")
    if caseType == "C" or caseType == "Z":
        zhExt = mf.getLayerExtent(zhLyr) = 1500
    elif caseType == "S":
        suExt = mf.getLayerExtent(suLyr) = 1500

The problem is the layer variable. It's defined in the first loop and I don't know if there's a way to recall it in the second loop. Maybe the loops have to be nested, but I'm having trouble figuring out how to do that properly. Thank you for any help!