I have created a script (see below) that works ok but only in case if all parameters are required inputs. Quite simple, Roads(line) and Tracts(polygon) feature classes , first buffer Roads and then clip to Tracts. There are more feature classes in Zion.gdb but I am just doing a test script to figure out optional input parameters.
What I need is that user should be able to select the layer they want to buffer, the layer they want to clip, the output location/name of the clip, and the buffer distance. All of it has to be optional. The problem is when I set for example Tracts and Tracts_Clip feature classes to optional in Script Parameters and do not apply them in script execution because I want only Roads buffer, the script does not work. Disregard red x symbol, I shortened the path.
Any help would be much appreciated!!!
<CODE><SPAN class=""> </SPAN><CODE><SPAN class=""> import</SPAN><SPAN class=""> arcpy</SPAN> <SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">from</SPAN> arcpy <SPAN class="keyword token">import</SPAN> env
<SPAN class="comment token"># set environment settings</SPAN>
env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> <SPAN class="string token">"C:/data/Zion.gdb"</SPAN>
env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
<SPAN class="comment token"># Script arguments</SPAN>
Roads <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>
<SPAN class="keyword token">if</SPAN> Roads <SPAN class="operator token">==</SPAN> '<SPAN class="comment token">#' or not Roads: </SPAN>
Roads <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> <SPAN class="comment token"># provide a default value if unspecified</SPAN>
Tracts <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> Tracts <SPAN class="operator token">==</SPAN> '<SPAN class="comment token">#' or not Tracts:</SPAN>
Tracts <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># provide a default value if unspecified</SPAN>
Tracts_Clip <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> Tracts_Clip <SPAN class="operator token">==</SPAN> '<SPAN class="comment token">#' or not Tracts_Clip:</SPAN>
Tracts_Clip <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># provide a default value if unspecified</SPAN>
Buffer_Distance <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> Buffer_Distance <SPAN class="operator token">==</SPAN> '<SPAN class="comment token">#' or not Buffer_Distance:</SPAN>
Buffer_Distance <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># provide a default value if unspecified</SPAN>
<SPAN class="comment token"># Local variables:</SPAN>
Tracts_Clip <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN>
Buffer_Distance <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">)</SPAN>
Roads_Buffer <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Roads_Buffer"</SPAN>
<SPAN class="comment token"># Process: Buffer</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Buffer_analysis<SPAN class="punctuation token">(</SPAN>Roads<SPAN class="punctuation token">,</SPAN> Roads_Buffer<SPAN class="punctuation token">,</SPAN> Buffer_Distance<SPAN class="punctuation token">,</SPAN><SPAN class="string token">"FULL"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"ROUND"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"ALL"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Process: Clip (1)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Clip_analysis<SPAN class="punctuation token">(</SPAN>Tracts<SPAN class="punctuation token">,</SPAN> Roads_Buffer<SPAN class="punctuation token">,</SPAN> Tracts_Clip<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><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><CODE><SPAN class=""> </SPAN>
<SPAN class=""></SPAN><SPAN class=""> </SPAN><SPAN class=""></SPAN><SPAN class=""></SPAN><SPAN class=""><BR /></SPAN>