AnsweredAssumed Answered

Counter for While iteration in the model builder

Question asked by ales.singli on Nov 7, 2016
Latest reply on Nov 10, 2016 by ales.singli

Hi everyone,

 

I'm using ArcGis 10.3. I am on the model builder and I have a While iteration. What I want to do is to create a counter: a variable x which is initialized with the value 1 and add +1 at every run, so the variable x actually shows the number of run.

This is because I want to use that value for saving data with in-line substitution (...%x%...).

You can see attached my first attempt. Basically  my Continue is a precondition for Calculate value (2) and the code in it is:

Expression: x("%Continue%")

def x(n):
 if n== "true":
  x=x+1

 

but I got this error:

ERROR 000539: Error running expression: counter("true")
Traceback (most recent call last):
  File "<expression>", line 1, in <module>
  File "<string>", line 3, in counter
UnboundLocalError: local variable 'counter' referenced before assignment

Is there a nicest and easiest way to create a counter?

(Basically the For iteration has it automatically as the Value, but the While lacked of a variable which takes account of the run)

 

Alessandro

Attachments

Outcomes