Check for certain field name and field type doesn't work

305
2
Jump to solution
02-01-2023 11:39 PM
JohannesBierer
Occasional Contributor III

Hello,

I want to check if a field type is text to change this field to type double so that I can use it as input field into XYTableToPoint?

This if statement in line 16 doesn't work (arcgis pro 3.0 notebook)

Any ideas?

Error message for line 41:

ERROR 000308: Ungültiger Feldtyp

 

 

 

for f in files_list:
    print (f)
    
    outTable = "tab_" + os.path.splitext(os.path.basename(f.replace("-", "_")))[0]
    outXY =  "s_" + os.path.splitext(os.path.basename(f.replace("-", "_")))[0]

    arcpy.conversion.ExcelToTable(f, outTable)
        
    x = "R_Wert"
    y = "H_Wert"
    
    fields = arcpy.ListFields(outTable)
    field_names = []
    for field in fields:
        field_names.append(field.name)
        if field.name == x and field.type == "TEXT":
            
            print("Wrong type")
            
            arcpy.management.AddField(outTable, "R_Wert_1", "DOUBLE")
            arcpy.management.CalculateField(outTable, "R_Wert_1", 
                                '!R_Wert!', "PYTHON3")
            x = "R_Wert_1"
                    
        elif field.name == y and field.type == "TEXT":
            
            print("Wrong Type")
            
            arcpy.management.AddField(outTable, "HWert_1", "DOUBLE")
            arcpy.management.CalculateField(outTable, "R_Wert_1", 
                                '!H_Wert!', "PYTHON3")
            y = "H_Wert_1"
            
        else:
            continue    
    
    if x in field_names and y in field_names:
        
        print("Field names ok")
        
        arcpy.management.XYTableToPoint(outTable, outXY,
                                        x, y, "",
                                        arcpy.SpatialReference("DHDN 3-Degree Gauss Zone 3"))# ('ETRS 1989 UTM Zone 32N'))
        
        
    else:
        print("Field names wrong")
        continue

 

 

 

 

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

Field—ArcGIS Pro | Dokumentation

Although the Field object's type property values are not an exact match for the keywords used by the Add Field tool's field_type parameter, all of the Field object's type values can be used as input to this parameter. The different field types are mapped as follows: Integer to LONGString to TEXT, and SmallInteger to SHORT.

 

 

if field.name == x and field.type == "String"

 

 

 


Have a great day!
Johannes

View solution in original post

0 Kudos
2 Replies
JohannesLindner
MVP Frequent Contributor

Field—ArcGIS Pro | Dokumentation

Although the Field object's type property values are not an exact match for the keywords used by the Add Field tool's field_type parameter, all of the Field object's type values can be used as input to this parameter. The different field types are mapped as follows: Integer to LONGString to TEXT, and SmallInteger to SHORT.

 

 

if field.name == x and field.type == "String"

 

 

 


Have a great day!
Johannes
0 Kudos
JohannesBierer
Occasional Contributor III

Thank you ...

0 Kudos