1

I am creating a tool in ArcGIS Pro where a part of the code creates a feature class (low_fuel_warning) and adds fields to it. When running the code in the Jupyter Notebook in ArcGIS, it works as it should. However, when running the code in a tool, it only creates a feature class but fails to add any fields.

What could the reason behind this be?

workspace = path to workspace

#  Create feature class low_fuel_warning
low_fuel_warning = arcpy.CreateFeatureclass_management(out_path=workspace, out_name="low_fuel_warning", geometry_type="POINT", template=[], has_m="DISABLED", has_z="DISABLED", spatial_reference="", config_keyword="", spatial_grid_1=0, spatial_grid_2=0, spatial_grid_3=0, out_alias="")

# Add field "fuel level", "distance", and "origin" to feature class
low_fuel_warning = arcpy.AddField_management(in_table="low_fuel_warning", field_name="fuel_level", field_type="DOUBLE", field_precision=None, field_scale=None, field_length=None, field_alias="", field_is_nullable="NULLABLE", field_is_required="NON_REQUIRED", field_domain="")

low_fuel_warning = arcpy.AddField_management(in_table="low_fuel_warning", field_name="distance", field_type="DOUBLE", field_precision=None, field_scale=None, field_length=None, field_alias="", field_is_nullable="NULLABLE", field_is_required="NON_REQUIRED", field_domain="")

low_fuel_warning = arcpy.AddField_management(in_table="low_fuel_warning", field_name="origin", field_type="TEXT", field_precision=None, field_scale=None, field_length=None, field_alias="", field_is_nullable="NULLABLE", field_is_required="NON_REQUIRED", field_domain="")[0]
0

1 Answer 1

3

Your field origin cannot have a field length of None it must be X number of characters. Also and I see this regularly in beginner coders is that they give a misleading name to the result object and treat it as dataset. So in your code low_fuel_warning is actually a result object as all geoprocessing tools return result objects which have their own set of properties. You also don't appear to be even using it, so why even reference it? I would recommend you call it something like resObj so its explicit as what it is and easier to understand.

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.