I am creating a model in gis ModelBuilder. I want to check the type of a particular field and

  1. if it is long integer than the tools should be different and
  2. else (i.e. not a long integer) my tools are different.

Is there a way to check the field or any already available python script which could help me do this?

  • 1
    gis.stackexchange.com/q/151937/115 will help you do this. – PolyGeo Dec 10 '17 at 6:09
  • 1
    There is no out of the box tool that can do this, this needs to be done with a little bit of scripting, @PolyGeo link will help. – Hornbydd Dec 11 '17 at 10:08
  1. Save the following code as a .py file. Change YOURFIELD to the field name of your field that you are trying to test.

    input = arcpy.GetParameterAsText(0)
    infc = arcpy.mapping.Layer(input)
    def testfld(infc):
        field = arcpy.ListFields(infc,"YOURFIELD")[0]
        type = field.type
        if type == 'Integer':
            arcpy.SetParameterAsText(1, "true")
            arcpy.SetParameterAsText(2, "false")
            arcpy.AddMessage("Long Integer Field")
            arcpy.SetParameterAsText(2, "true")
            arcpy.SetParameterAsText(1, "false")
            arcpy.AddMessage(str(field.type) + " Field")
  2. Create a Script tool, use the .py file you just created as the Script File:

enter image description here

  1. Set the parameters for the tool:
    • Input Feature Class - Type=Feature Layer, Direction=Input
    • Long Integer Field - Type=Boolean, Direction=Output
    • Other Field Type - Type=Boolean, Direction=Output

enter image description here

  1. Add the script tool into your model. Connect 'Other Field Type' as a precondition to the tools you want to run if the field is not Long Int. Connect 'Long Integer Field' as a precondition to the tools you want to run if the field is Long Int:

enter image description here

When the precondition is false, the tools won't run. If the field is Long Int, the tools for processing long integer fields will run and the other tools will not run and vice versa.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.