Hello, I have different methods within the same script tool how I can apply filter so that the user will select different method and run code
If I understand you correctly, you have a function with 3 parameters:
To use this function inside a script tool, you have to define 3 parameters for the tool:
In the method parameter, define a filter list with valid method names. This way, you have a dropdown list with predefined things like "warp", "edge", etc.
Then you change your script:
<SPAN class="comment token"># imports</SPAN> <SPAN class="comment token"># get the script parameters</SPAN> raster_param <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> scale_param <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"># convert to int or float as needed</SPAN> method_param <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"># this parameter has a filter list,</SPAN> <SPAN class="comment token"># so you know it can only be "warp" or "edge".</SPAN> <SPAN class="comment token"># define your function (I think you already have that)</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">your_function</SPAN><SPAN class="punctuation token">(</SPAN>raster<SPAN class="punctuation token">,</SPAN> scale<SPAN class="punctuation token">,</SPAN> method<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># stuff</SPAN> <SPAN class="keyword token">if</SPAN> method <SPAN class="operator token">==</SPAN> <SPAN class="string token">"warp"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># warp implementation</SPAN> <SPAN class="keyword token">if</SPAN> method <SPAN class="operator token">==</SPAN> <SPAN class="string token">"edge"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># edge implementation</SPAN> <SPAN class="comment token"># more stuff</SPAN> <SPAN class="comment token"># call your function</SPAN> your_function<SPAN class="punctuation token">(</SPAN>raster_param<SPAN class="punctuation token">,</SPAN> scale_param<SPAN class="punctuation token">,</SPAN> method_param<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>
Thanks for your reply, Sure I am trying to use ready function that need arguments such (raster, scale , and method)
what I need the user to select the method from drop down menu and run the tool ?
Mina Alsaad, I read your question and your responses, and I am having a hard time figuring out your question. I realize there may be a language barrier occurring, but that makes it even more important to provide specifics and examples rather than speaking in general.
Dan Patterson What I meant only I want to change one parameter and run the tool?
Dan Patterson Thanks for your reply, what I want to do to call one function rescale (input, mode, other parameters)
inside mode there is different method {edge, warp,}, if the user select one of the method it will be different result ?
for one of your parameters, define it as a text parameter and make a value list with your options.
For each option, create a def that performs the task
<SPAN class="keyword token">import</SPAN> blah method <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"># a value list of the method names</SPAN> params <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">def</SPAN> <SPAN class="token function">method1</SPAN><SPAN class="punctuation token">(</SPAN>params<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"""method1 functionality"""</SPAN> Do stuff <SPAN class="keyword token">return</SPAN> something <SPAN class="keyword token">def</SPAN> <SPAN class="token function">method2</SPAN><SPAN class="punctuation token">(</SPAN>params<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"""method2 functionality"""</SPAN> Do stuff <SPAN class="keyword token">return</SPAN> something <SPAN class="keyword token">if</SPAN> method <SPAN class="operator token">==</SPAN> <SPAN class="string token">"first"</SPAN><SPAN class="punctuation token">:</SPAN> result <SPAN class="operator token">=</SPAN> method1<SPAN class="punctuation token">(</SPAN>params<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN> result <SPAN class="operator token">=</SPAN> method2<SPAN class="punctuation token">(</SPAN>params<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Here is the amazing result : {}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>result<SPAN class="punctuation 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>
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.