I am trying to use python to calculate a field first to put sequential numbers, then pad with leading zeros, then finally to concatenate with a code for each data layer. I set the parameters as the layer, the field, and the 4 digit code. The script that I am using is below. I keep getting an error 539 in the add leading zeros function which says the IDPK_Field is not defined. I am not the best at python, any help would be appreciated!
<SPAN class="keyword token">import</SPAN> arcpy
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">False</SPAN>
<SPAN class="comment token"># Script parameters</SPAN>
Input_Layer <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN>
IDPK_Field <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN>
CALField <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Local variables:</SPAN>
Updated_Input_Table <SPAN class="operator token">=</SPAN> Input_Layer
Updated_Input_Table__2_ <SPAN class="operator token">=</SPAN> Updated_Input_Table
Updated_Input_Table__3_ <SPAN class="operator token">=</SPAN> Updated_Input_Table__2_
<SPAN class="comment token">#Add Sequental Number</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>CalculateField_management<SPAN class="punctuation token">(</SPAN>in_table<SPAN class="operator token">=</SPAN>Input_Layer<SPAN class="punctuation token">,</SPAN> field<SPAN class="operator token">=</SPAN>IDPK_Field<SPAN class="punctuation token">,</SPAN> expression<SPAN class="operator token">=</SPAN><SPAN class="string token">"autoIncrement()"</SPAN><SPAN class="punctuation token">,</SPAN> expression_type<SPAN class="operator token">=</SPAN><SPAN class="string token">"PYTHON3"</SPAN><SPAN class="punctuation token">,</SPAN> code_block<SPAN class="operator token">=</SPAN><SPAN class="string token">"""rec=0
def autoIncrement():
global rec
pStart = 1
pInterval = 1
if (rec == 0):
rec = pStart
else:
rec = rec + pInterval
return rec"""</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#Add Leading Zeros</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>CalculateField_management<SPAN class="punctuation token">(</SPAN>in_table<SPAN class="operator token">=</SPAN>Updated_Input_Table<SPAN class="punctuation token">,</SPAN> field<SPAN class="operator token">=</SPAN> IDPK_Field<SPAN class="punctuation token">,</SPAN> expression<SPAN class="operator token">=</SPAN><SPAN class="string token">"str(IDPK_Field).zfill(6)"</SPAN><SPAN class="punctuation token">,</SPAN> expression_type<SPAN class="operator token">=</SPAN><SPAN class="string token">"PYTHON3"</SPAN><SPAN class="punctuation token">,</SPAN> code_block<SPAN class="operator token">=</SPAN><SPAN class="string token">""</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#Add layer Code</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>CalculateField_management<SPAN class="punctuation token">(</SPAN>in_table<SPAN class="operator token">=</SPAN>Updated_Input_Table__2_<SPAN class="punctuation token">,</SPAN> field<SPAN class="operator token">=</SPAN>IDPK_Field<SPAN class="punctuation token">,</SPAN> expression<SPAN class="operator token">=</SPAN><SPAN class="string token">"CALField + IDPK_Field"</SPAN><SPAN class="punctuation token">,</SPAN> expression_type<SPAN class="operator token">=</SPAN><SPAN class="string token">"PYTHON3"</SPAN><SPAN class="punctuation token">,</SPAN> code_block<SPAN class="operator token">=</SPAN><SPAN class="string token">""</SPAN><SPAN class="punctuation token">)</SPAN><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></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>