Hi All. I'm trying to run the below python code with no luck. The 2 layers listed on line 20 are referenced again on line 37 when I attempt to cycle through their extents. The code should pull the extents and apply them to the data frame. The issue is that the list at line 20 won't work unless there are no spaces in the layer names. If enclose the names in "..." then the code is "syntax error free" but fails at line 37 when trying to extract the extent of a string object instead of a layer. How can I work around this (would prefer to not have to rename my layers in the mxd!).
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">from</SPAN> arcpy <SPAN class="keyword token">import</SPAN> env<SPAN class="punctuation token">,</SPAN> mapping
<SPAN class="keyword token">from</SPAN> bisect <SPAN class="keyword token">import</SPAN> bisect
<SPAN class="comment token">#input parameters;</SPAN>
Plantation <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameter<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN>
ForestID <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameter<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN>
CommonName <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameter<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN>
PYear <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameter<SPAN class="punctuation token">(</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">)</SPAN>
OpCode <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameter<SPAN class="punctuation token">(</SPAN><SPAN class="number token">4</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#variables;</SPAN>
title1 <SPAN class="operator token">=</SPAN> Plantation <SPAN class="operator token">+</SPAN> <SPAN class="string token">" PLANTATION"</SPAN>
title2 <SPAN class="operator token">=</SPAN> Plantation <SPAN class="operator token">+</SPAN> <SPAN class="string token">"\r\nPLANTATION"</SPAN>
title3 <SPAN class="operator token">=</SPAN> Plantation <SPAN class="operator token">+</SPAN> <SPAN class="string token">" ("</SPAN> <SPAN class="operator token">+</SPAN> CommonName <SPAN class="operator token">+</SPAN> <SPAN class="string token">")"</SPAN>
title4 <SPAN class="operator token">=</SPAN> Plantation <SPAN class="operator token">+</SPAN> <SPAN class="string token">" P"</SPAN> <SPAN class="operator token">+</SPAN> PYear <SPAN class="operator token">+</SPAN> <SPAN class="string token">" AREA STATEMENT"</SPAN>
mxd <SPAN class="operator token">=</SPAN> mapping<SPAN class="punctuation token">.</SPAN>MapDocument<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"CURRENT"</SPAN><SPAN class="punctuation token">)</SPAN>
elements <SPAN class="operator token">=</SPAN> mapping<SPAN class="punctuation token">.</SPAN>ListLayoutElements<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">)</SPAN>
layers <SPAN class="operator token">=</SPAN> mapping<SPAN class="punctuation token">.</SPAN>ListLayers<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">)</SPAN>
HTL_layer_list <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"Entered In GeoMaster"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Entered In GeoMaster Archive"</SPAN><SPAN class="punctuation token">]</SPAN>
dflist <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ListDataFrames<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">)</SPAN>
opcode_exp1 <SPAN class="operator token">=</SPAN> <SPAN class="string token">"EnteredInGeoMaster IS NOT NULL AND Ops_Code = '"</SPAN> <SPAN class="operator token">+</SPAN> OpCode <SPAN class="operator token">+</SPAN> <SPAN class="string token">"'"</SPAN>
opcode_exp2 <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Ops_Code = '"</SPAN> <SPAN class="operator token">+</SPAN> OpCode <SPAN class="operator token">+</SPAN> <SPAN class="string token">"'"</SPAN>
<SPAN class="keyword token">if</SPAN> lyr<SPAN class="punctuation token">.</SPAN>name <SPAN class="operator token">==</SPAN> <SPAN class="string token">"Entered In GeoMaster"</SPAN><SPAN class="punctuation token">:</SPAN>
lyr<SPAN class="punctuation token">.</SPAN>definitionQuery <SPAN class="operator token">=</SPAN> opcode_exp1
arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN>lyr<SPAN class="punctuation token">.</SPAN>name <SPAN class="operator token">+</SPAN> <SPAN class="string token">" definition query updated"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">elif</SPAN> lyr<SPAN class="punctuation token">.</SPAN>name <SPAN class="operator token">==</SPAN> <SPAN class="string token">"Entered In GeoMaster Archive"</SPAN><SPAN class="punctuation token">:</SPAN>
lyr<SPAN class="punctuation token">.</SPAN>definitionQuery <SPAN class="operator token">=</SPAN> opcode_exp2
arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN>lyr<SPAN class="punctuation token">.</SPAN>name <SPAN class="operator token">+</SPAN> <SPAN class="string token">" definition query updated"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># get current map extent</SPAN>
xmin<SPAN class="punctuation token">,</SPAN> xmax <SPAN class="operator token">=</SPAN> dflist<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">.</SPAN>XMin<SPAN class="punctuation token">,</SPAN> dflist<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">.</SPAN>XMax
ymin<SPAN class="punctuation token">,</SPAN> ymax <SPAN class="operator token">=</SPAN> dflist<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">.</SPAN>YMin<SPAN class="punctuation token">,</SPAN> dflist<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">.</SPAN>YMax
<SPAN class="comment token"># loop through def query layer extents and create one extent to fit them all</SPAN>
<SPAN class="keyword token">for</SPAN> HTL_lyr <SPAN class="keyword token">in</SPAN> HTL_layer_list<SPAN class="punctuation token">:</SPAN>
HTL_ext <SPAN class="operator token">=</SPAN> HTL_lyr<SPAN class="punctuation token">.</SPAN>getExtent<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> HTL_ext<SPAN class="punctuation token">.</SPAN>XMin <SPAN class="operator token"><</SPAN> xmin<SPAN class="punctuation token">:</SPAN>
xmin <SPAN class="operator token">=</SPAN> ext<SPAN class="punctuation token">.</SPAN>XMin
<SPAN class="keyword token">if</SPAN> HTL_ext<SPAN class="punctuation token">.</SPAN>YMin <SPAN class="operator token"><</SPAN> ymin<SPAN class="punctuation token">:</SPAN>
ymin <SPAN class="operator token">=</SPAN> ext<SPAN class="punctuation token">.</SPAN>YMin
<SPAN class="keyword token">if</SPAN> HTL_ext<SPAN class="punctuation token">.</SPAN>XMax <SPAN class="operator token">></SPAN> xmax<SPAN class="punctuation token">:</SPAN>
xmax <SPAN class="operator token">=</SPAN> ext<SPAN class="punctuation token">.</SPAN>XMax
<SPAN class="keyword token">if</SPAN> HTL_ext<SPAN class="punctuation token">.</SPAN>YMax <SPAN class="operator token">></SPAN> ymax<SPAN class="punctuation token">:</SPAN>
ymax <SPAN class="operator token">=</SPAN> ext<SPAN class="punctuation token">.</SPAN>YMax
<SPAN class="comment token"># set df extent to new extent</SPAN>
dflist<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>extent <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Extent<SPAN class="punctuation token">(</SPAN>xmin<SPAN class="punctuation token">,</SPAN> ymin<SPAN class="punctuation token">,</SPAN> xmax<SPAN class="punctuation token">,</SPAN> ymax<SPAN class="punctuation token">)</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></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><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></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>