I have the following code:
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">from</SPAN> arcpy <SPAN class="keyword token">import</SPAN> env
env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"PATH\SDE_CONNECTION.sde"</SPAN>
mxd <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation 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>
df <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><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># Variables</SPAN>
subbasinCode <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN>
pdfName <SPAN class="operator token">=</SPAN> subbasinCode <SPAN class="operator token">+</SPAN> <SPAN class="string token">".pdf"</SPAN>
queryString <SPAN class="operator token">=</SPAN> <SPAN class="string token">"AREA_CODE ="</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"'"</SPAN> <SPAN class="operator token">+</SPAN> subbasinCode <SPAN class="operator token">+</SPAN> <SPAN class="string token">"'"</SPAN>
subbasins <SPAN class="operator token">=</SPAN> <SPAN class="string token">"SDE.SEWERMAN.SUBBASIN"</SPAN>
subbasinSymbol <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"PATH\Subbasin_Selection.lyr"</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN>subbasinCode<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN>queryString<SPAN class="punctuation token">)</SPAN>
subbasinSelect <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>MakeFeatureLayer_management<SPAN class="punctuation token">(</SPAN>subbasins<SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"Subbasin_Selection"</SPAN><SPAN class="punctuation token">,</SPAN>
queryString<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN>subbasinSelect<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># arcpy.GetMessages()</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>ApplySymbologyFromLayer_management<SPAN class="punctuation token">(</SPAN>subbasinSelect<SPAN class="punctuation token">,</SPAN> subbasinSymbol<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Symbology applied to subbasin selection."</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># arcpy.GetMessages()</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>
When I run this code in the python console in ArcMap (hardcode the subbasinCode variable) it runs fine. It replaces the existing Subbasin_Selection layer with the new selection from the MakeFeatureLayer function then applies the symbology.
When I create the script tool and run it the original Subbasin_Selection layer is removed from the map but the new subbasin isn't added.
The original code was much longer and it would use data driven pages to create a map book and export it based on the subbasin selection. It ran fine a a standalone script. I simplified it to figure out what is going on.
Any ideas on why it won't work in a script tool?


