....stuff before if (Z > 0) and (AF > 0): x = sum( [T, Z, AF] ) #or x = T + Z + AF elif (Z > 0) and (AF < 0): x = sum( [T, Z ] ) #or x = T + Z elif (Z < 0) and (AF > 0): x = sum( [T, AF] ) #or x = T + AF else: x = T .... stuff after
if [condition 1]: # first condition to check [set field value] elif [condition n]: # you'll have several instances of this for every other condition [set field value] else: # no other conditions matched [set field value] [update the row] [move to the next row]
FC = gp.GetParameterAsText(0) Z = gp.GetParameterAsText(1) AF = gp.GetParameterAsText(2) T = gp.GetParameterAsText(3) Outfield = gp.GetParameterAsText(4) cur = gp.UpdateCursor(FC) row = cur.Next() while row: if (Z > 0) and (AF > 0): Outfield = T + Z + AF #or = sum( [T, Z, AF] ) elif (Z > 0) and (AF < 0): Outfield = T + Z #or = sum( [T, Z ] ) elif (Z < 0) and (AF > 0): Outfield = T + AF #or = sum( [T, AF] ) else: Outfield = T del cur
while row: if (Z > 0) and (AF > 0): Outfield = T + Z + AF #or = sum( [T, Z, AF] ) elif (Z > 0) and (AF < 0): Outfield = T + Z #or = sum( [T, Z ] ) elif (Z < 0) and (AF > 0): Outfield = T + AF #or = sum( [T, AF] ) else: Outfield = T row = cur.next() # <-------------missing the move to the next row
I think I am close (with your help of course); but what do you think is wrong with this? It runs without completing, on a relativley small sample.FC = gp.GetParameterAsText(0) Z = gp.GetParameterAsText(1) AF = gp.GetParameterAsText(2) T = gp.GetParameterAsText(3) Outfield = gp.GetParameterAsText(4) cur = gp.UpdateCursor(FC) row = cur.Next() while row: if (Z > 0) and (AF > 0): Outfield = T + Z + AF #or = sum( [T, Z, AF] ) elif (Z > 0) and (AF < 0): Outfield = T + Z #or = sum( [T, Z ] ) elif (Z < 0) and (AF > 0): Outfield = T + AF #or = sum( [T, AF] ) else: Outfield = T del cur
FC = gp.GetParameterAsText(0) Z = gp.GetParameterAsText(1) AF = gp.GetParameterAsText(2) T = gp.GetParameterAsText(3) Outfield = gp.GetParameterAsText(4) cur = gp.UpdateCursor(FC) row = cur.Next() while row: if (Z > 0) and (AF > 0): row.SetValue(Outfield, T + Z + AF) #or = sum( [T, Z, AF] ) cur.UpdateRow(row) elif (Z > 0) and (AF < 0): row.SetValue(Outfield, T + Z) #or = sum( [T, Z ] ) cur.UpdateRow(row) elif (Z < 0) and (AF > 0): row.SetValue(Outfield, T + AF) #or = sum( [T, AF] ) cur.UpdateRow(row) else: row.SetValue(Outfield, T) cur.UpdateRow(row) row = cur.Next() del cur
if (Z > 0) and (AF > 0): val = T + Z + AF #or = sum( [T, Z, AF] ) row.SetValue(Outfield, val) cur.UpdateRow(row)