Hello,
Trying to figure out how to use the Get Count Tool as a variable and to use it in a field calculator expression. Tried to use inline variable substitution but it is not working properly and giving me an error related to string/interger. The Row Count is set as a precondition. Attached is a photo for reference. any advice would be well appreciated!
My suggestion is to calculate your value first using the Calculate Value tool.
Set the Row Count as precondition to the Calculate Value tool
Calculate Value Expression: ((%Row Count% + 1) / 2
Calculate Value output data type: Expression
Then you can connect the output of the Calculate Value to your Calculate Field tool as an input parameter.
I have spoofed up a similar situation as shown below.
If I attempt to validate the expression I get a Syntax Error as shown above.
If I IGNORE that error message and run the model it runs without error!
ok try this (sentences which start with a # are just comments to you, not part of the code).
<SPAN class="comment token"># insert this where it says 'code block'</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">func</SPAN><SPAN class="punctuation token">(</SPAN>field<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> result <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>float<SPAN class="punctuation token">(</SPAN>field<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="number token">1.0</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="operator token">/</SPAN> <SPAN class="number token">2.0</SPAN> <SPAN class="keyword token">return</SPAN> result <SPAN class="comment token">#put this where it says Med_PS =</SPAN> func<SPAN class="punctuation token">(</SPAN><SPAN class="operator token">%</SPAN>Row Count<SPAN class="operator token">%</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">#if that doesnt work try changing the 'code block' to</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">func</SPAN><SPAN class="punctuation token">(</SPAN>field<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> result <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>float<SPAN class="punctuation token">(</SPAN>field<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="number token">1.0</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="operator token">/</SPAN> <SPAN class="number token">2.0</SPAN> <SPAN class="keyword token">return</SPAN> result <SPAN class="comment token">#if that doesnt work try changing the 'code block' to</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">func</SPAN><SPAN class="punctuation token">(</SPAN>field<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> result <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>float<SPAN class="punctuation token">(</SPAN>field<SPAN class="punctuation token">.</SPAN>getOutput<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="number token">1.0</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="operator token">/</SPAN> <SPAN class="number token">2.0</SPAN> <SPAN class="keyword token">return</SPAN> result <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>
Tried without the quotations and it only works without any other numbers in the box
Can you try without the quotations around Row Count
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.