Hey guys. I am creating a python toolbox that assigns selected polygons in a shapefile a unique id. This id features a section of string followed by a sequential ID. However, whenever I insert the following code block for autoIncrement into my script, the tool will no longer launch. This is the autoincrement block I have taken from ArcGIS Resources:
rec = 0
def autoIncrement():
global rec
pStart = 1 #adjust start value, if req'd
pInterval = 1 #adjust interval value, if req'd
if (rec == 0):
rec = pStart
else:
rec = rec + pInterval
return rec
I am placing it in the " def execute(self, parameters, messages):" section of the python toolbox template.
Any ideas as to why this is causing my script to fail? Thank you!
Solved! Go to Solution.
Ah - now I see. Lines 12 and 13 are indented incorrectly.
It would be most helpful if you could post the error message, as well as the complete python file. I don't think there is anything wrong with the snippet you posted so there must be something else. Thanks
I'm afraid there is no error message. Where I can usually select the script (seen here as "Tool")...
... After pasting in that code block into the script, the option disappears as shown here:...
If you right click on TestToolbox.pyt do you get an option to "Check Syntax"?
Here's the error:
For context, here's this part of the code:
def execute(self, parameters, messages):
# Sequential Formula
rec = 0
def autoIncrement():
global rec
pStart = 1 #adjust start value, if req'd
pInterval = 1 #adjust interval value, if req'd
if (rec == 0):
rec = pStart
else:
rec = rec + pInterval
return rec
Apologies for the lack of clarity. Line 112 is line 12 in my pasted code.
Ah - now I see. Lines 12 and 13 are indented incorrectly.
Wow, how foolish of me. Thank you! Think I've been staring at code for too long.