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:
if n== "true":
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)
You say that Calculate value (2) has the expression:
if n== "true":
But the error message is about counter("true")? You need to show us the whole model or upload it as a zip file as what you are asking is not clear.
Also look at the help file for the subject Examples of in-line variable substitution with ModelBuilder system variables there are two system variables %i% and %n% accessible to you in model builder, may be they are what you are looking for?
Yes I was actually trying to build a counter to use for in-line substitution. It sounds like the %n% system variable does all the job, there is no need to build anything.