How can I set my tool boolean parameter to true in my arcpy script?

02-02-2022 05:53 PM
New Contributor III

I have set one my ArcGIS Pro tool's parameter as optional to auto populate a field ID if the field ID is missing. However, when I tried to populate the field ID, it does not work. How do I set my boolean parameter to true in my script to populated the required ID field?  (On a side note, the "with arcpy.da.SearchCursor" block is meant to search in the first row of the column, OBJECTID to determine if it is zero; if the condition is true, then it will calculate the field ID with "!OBJECTID!+1" and if not, it will use "!OBJECTID!", because the ID needs to start with 1. Is there a better way of writing this part of the script? Not my main question, but just curious for other suggestion. Thanks everyone! )

CreatePPTFieldID = arcpy.GetParameterAsText(8)

#Creating the field ID
if (CreatePPTFieldID = "True"):,"ID","Long")
   with arcpy.da.SearchCursor(inpourpoint, 'OBJECTID') as cursor:
      for row in cursor:
         if (row[0]==0):

0 Kudos
2 Replies
MVP Esteemed Contributor

(CreatePPTFieldID = "True") is an assignment statement

(CreatePPTFieldID == "True") is a condition statement

throw in a print statement to make sure it is returning a text string ("True" ) and not a boolean ( True )

exit() isn't needed

... sort of retired...
0 Kudos
New Contributor III

@DanPattersonI think the respond is a few lines before. tzz_12 when you are getting values from toolbox, you can get the variables as TEXT or as 'they are'. so try instead

CreatePPTFieldID = arcpy.GetParameterAsText(8)

CreatePPTFieldID = arcpy.GetParameter(8)


0 Kudos