Hi,
I am trying to create a model where I add multiple new fields to a feature class and to do some other geoprocessing tasks. Is there a way to choose what the field names will be based on user input? I have one field that I add to the feature class which depends on what the data represents and I was wondering if there is a way where I can when running the model select one of two options to what the field should be called. I also wanted to do it so that I could select whether it will add the WAperiod field. I am pretty new to this so I can imagine its something very simple
Brilliant! thanks for the help guys
It's pretty easy to create a string parameter value filter to set the choices to a limited list of strings. When the model tool is run, it will present a picklist of keywords (which can be the same as the list of field names you want).
Value list filter—Help | ArcGIS Desktop
Model parameters—ArcGIS Pro | ArcGIS Desktop
If you want the model to figure out the name without the user having to know, branching your model (as Dan suggests) is an option, but I think it's easier to use Calculate Value to calculate your field name. Either approach will require some scripting.
<SPAN class="comment token"># Calculate Value Expression</SPAN> GetFieldName<SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">"%table%"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># Code Block</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">GetFieldName</SPAN><SPAN class="punctuation token">(</SPAN>tbl<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># use field name to figure out what sort of table, </SPAN> <SPAN class="comment token"># if KEYFIELD is not there, returns empty (false)</SPAN> <SPAN class="comment token"># and field name is assigned "FIELDNAME2"</SPAN> <SPAN class="keyword token">if</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFields<SPAN class="punctuation token">(</SPAN>tbl<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"KEYFIELD"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> fname <SPAN class="operator token">=</SPAN> <SPAN class="string token">"FIELDNAME1"</SPAN> <SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN> fname <SPAN class="operator token">=</SPAN> <SPAN class="string token">"FIELDNAME2"</SPAN> <SPAN class="keyword token">return</SPAN> fname <SPAN class="comment token"># Data Type</SPAN> String<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>
As for providing options as to which field name to choose, you can check the 'branching' section of modelbuilder to see how 'if-else' conditions are implemented.
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.