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 <SPAN class="operator token">=</SPAN> proj<SPAN class="punctuation token">.</SPAN>listMaps<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> m <SPAN class="keyword token">in</SPAN> maps<SPAN class="punctuation token">:</SPAN>
zhLyr <SPAN class="operator token">=</SPAN> m<SPAN class="punctuation token">.</SPAN>listLayers<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Zoning History"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
suLyr <SPAN class="operator token">=</SPAN> m<SPAN class="punctuation token">.</SPAN>listLayers<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Special Use Permit"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">if</SPAN> caseType <SPAN class="operator token">==</SPAN> <SPAN class="string token">"C"</SPAN> <SPAN class="operator token">or</SPAN> caseType <SPAN class="operator token">==</SPAN> <SPAN class="string token">"Z"</SPAN><SPAN class="punctuation token">:</SPAN>
zhLyr<SPAN class="punctuation token">.</SPAN>definitionQuery <SPAN class="operator token">=</SPAN> <SPAN class="string token">"CaseNumber = '"</SPAN> <SPAN class="operator token">+</SPAN> case <SPAN class="operator token">+</SPAN> <SPAN class="string token">"'"</SPAN>
zhLyr<SPAN class="punctuation token">.</SPAN>visible <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
suLyr<SPAN class="punctuation token">.</SPAN>visible <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">False</SPAN>
<SPAN class="keyword token">elif</SPAN> caseType <SPAN class="operator token">==</SPAN> <SPAN class="string token">"S"</SPAN><SPAN class="punctuation token">:</SPAN>
suLyr<SPAN class="punctuation token">.</SPAN>definitionQuery <SPAN class="operator token">=</SPAN> <SPAN class="string token">"CaseNumber = '"</SPAN> <SPAN class="operator token">+</SPAN> case <SPAN class="operator token">+</SPAN> <SPAN class="string token">"'"</SPAN>
suLyr<SPAN class="punctuation token">.</SPAN>visible <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
zhLyr<SPAN class="punctuation token">.</SPAN>visible <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">False</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>I conceptually know how to loop through the layouts and center them on the feature:
layouts <SPAN class="operator token">=</SPAN> proj<SPAN class="punctuation token">.</SPAN>listLayouts<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> l <SPAN class="keyword token">in</SPAN> layouts<SPAN class="punctuation token">:</SPAN>
mf <SPAN class="operator token">=</SPAN> l<SPAN class="punctuation token">.</SPAN>listElements<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"MAPFRAME_ELEMENT"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> caseType <SPAN class="operator token">==</SPAN> <SPAN class="string token">"C"</SPAN> <SPAN class="operator token">or</SPAN> caseType <SPAN class="operator token">==</SPAN> <SPAN class="string token">"Z"</SPAN><SPAN class="punctuation token">:</SPAN>
zhExt <SPAN class="operator token">=</SPAN> mf<SPAN class="punctuation token">.</SPAN>getLayerExtent<SPAN class="punctuation token">(</SPAN>zhLyr<SPAN class="punctuation token">)</SPAN>
mf<SPAN class="punctuation token">.</SPAN>camera<SPAN class="punctuation token">.</SPAN>setExtent<SPAN class="punctuation token">(</SPAN>zhExt<SPAN class="punctuation token">)</SPAN>
mf<SPAN class="punctuation token">.</SPAN>camera<SPAN class="punctuation token">.</SPAN>scale <SPAN class="operator token">=</SPAN> <SPAN class="number token">1500</SPAN>
<SPAN class="keyword token">elif</SPAN> caseType <SPAN class="operator token">==</SPAN> <SPAN class="string token">"S"</SPAN><SPAN class="punctuation token">:</SPAN>
suExt <SPAN class="operator token">=</SPAN> mf<SPAN class="punctuation token">.</SPAN>getLayerExtent<SPAN class="punctuation token">(</SPAN>suLyr<SPAN class="punctuation token">)</SPAN>
mf<SPAN class="punctuation token">.</SPAN>camera<SPAN class="punctuation token">.</SPAN>setExtent<SPAN class="punctuation token">(</SPAN>suExt<SPAN class="punctuation token">)</SPAN>
mf<SPAN class="punctuation token">.</SPAN>camera<SPAN class="punctuation token">.</SPAN>scale <SPAN class="operator token">=</SPAN> <SPAN class="number token">1500</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>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!