๐Ÿ” Extract Field Names Containing 'type' (Integer Fields Without Domain) from GDB Using ArcPy

  ⚙️ How the Script Works ๐Ÿ—‚️ Geodatabase Setup The script starts by pointing to a target File Geodatabase (.gdb) and initializing a CSV ...

Monday, May 19, 2025

๐Ÿ” Batch Field Updates in Multiple GDBs Using Arcade Expressions (ArcPy)

 

๐Ÿ” How the Script Works

๐Ÿ—‚ Directory Setup

The script begins by defining the main folder that contains all your .gdb files. It automatically loops through every GDB inside.

๐Ÿง  Arcade Expressions

You define a list of fields to update and the corresponding Arcade expressions that will be applied to each. Arcade allows you to build dynamic values based on feature attributes, domain values, or calculations.

In this example:

arcade
'UG/' + DomainName($feature, 'PortNameEg') + '/Photos/' + $feature.Photo

This constructs a folder path or URL-like string using the domain name of a field and another attribute.

๐Ÿ” Iterating Through GDBs

The script scans both:

  • Standalone feature classes (outside of datasets)

  • Feature classes inside feature datasets

๐Ÿงฎ Field Updates

It applies the Arcade expression to each field using arcpy.management.CalculateField(). If the field does not exist in a particular feature class, it simply skips it.


๐Ÿงพ The Code

python
import arcpy import os # === USER INPUT === # Folder containing GDBs gdb_folder = r'C:\Path\To\Your\GDBs' # Fields and corresponding Arcade expressions fields_to_update = ["PORTNAMEEG"] field_values_to_update = ["'UG/' + DomainName($feature, 'PortNameEg') + '/Photos/' + $feature.Photo"] # Loop through each GDB in the directory for folder in os.listdir(gdb_folder): if folder.endswith(".gdb"): gdb_path = os.path.join(gdb_folder, folder) arcpy.env.workspace = gdb_path # --- 1. Process standalone feature classes --- feature_classes = arcpy.ListFeatureClasses() for fc in feature_classes: print(f"Working on standalone Feature Class: {fc}") for field_name, arcade_expression in zip(fields_to_update, field_values_to_update): if arcpy.ListFields(fc, field_name): arcpy.management.CalculateField(fc, field_name, arcade_expression, "ARCADE") print(f"✅ Updated {field_name} in {fc}") else: print(f"⚠️ Field {field_name} not found in {fc}, skipping.") # --- 2. Process feature classes inside datasets --- datasets = arcpy.ListDatasets() or [] for ds in datasets: arcpy.env.workspace = os.path.join(gdb_path, ds) dataset_feature_classes = arcpy.ListFeatureClasses() for fc in dataset_feature_classes: print(f"Working on Feature Class: {fc} in Dataset: {ds}") for field_name, arcade_expression in zip(fields_to_update, field_values_to_update): if arcpy.ListFields(fc, field_name): arcpy.management.CalculateField(fc, field_name, arcade_expression, "ARCADE") print(f"✅ Updated {field_name} in {fc}") else: print(f"⚠️ Field {field_name} not found in {fc}, skipping.") print("\n✅ Field update process completed.")

๐Ÿ’ก Key Highlights

  • Uses Arcade expressions for dynamic, attribute-based field updates.

  • Supports both standalone and dataset-based feature classes.

  • Automatically scans and updates multiple geodatabases.

  • Safely skips fields that do not exist—no interruptions in the workflow.


✅ Use Case Scenarios

  • Generating dynamic paths or URLs for photos, reports, or documents.

  • Populating fields based on domain values (e.g., DomainName($feature, 'FieldName')).

  • Cleaning up and standardizing attribute fields after merges or imports.

  • Repeating field updates across multiple geodatabases with minimal effort.


✨ Pro Tip

You can expand this script by:

  • Adding logging to a .txt file.

  • Accepting folder paths and field info via a simple GUI or argparse CLI.

  • Converting it to a custom toolbox tool (.tbx) in ArcGIS Pro for team use.