ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Core.Data.DDL Namespace / FieldDescription Class / CreateObjectIDField Method
Example

In This Topic
    CreateObjectIDField Method
    In This Topic
    Creates a field description for an Object ID ArcGIS.Core.Data.Field.
    Syntax
    Public Shared Function CreateObjectIDField() As FieldDescription
    public static FieldDescription CreateObjectIDField()

    Return Value

    A field description for an Object ID ArcGIS.Core.Data.Field.
    Example
    Creating a Table
    {
      // Must be called within QueuedTask.Run
      void CreateTableSnippet(Geodatabase geodatabase, CodedValueDomain inspectionResultsDomain)
      {
        // Create a PoleInspection table with the following fields
        // GlobalID
        // ObjectID
        // InspectionDate (date)
        // InspectionResults (pre-existing InspectionResults coded value domain)
        // InspectionNotes (string)
    
        // This helper routine creates a FieldDescription for a GlobalID field with default values
        FieldDescription globalIDFieldDescription = FieldDescription.CreateGlobalIDField();
    
        // This helper routine creates a FieldDescription for an ObjectID field with default values
        FieldDescription objectIDFieldDescription = FieldDescription.CreateObjectIDField();
    
        // Create a FieldDescription for the InspectionDate field
        FieldDescription inspectionDateFieldDescription = new FieldDescription("InspectionDate", FieldType.Date)
        {
          AliasName = "Inspection Date"
        };
    
        // This helper routine creates a FieldDescription for a Domain field (from a pre-existing domain)
        FieldDescription inspectionResultsFieldDescription = FieldDescription.CreateDomainField("InspectionResults",
          new CodedValueDomainDescription(inspectionResultsDomain));
        inspectionResultsFieldDescription.AliasName = "Inspection Results";
    
        // This helper routine creates a FieldDescription for a string field
        FieldDescription inspectionNotesFieldDescription =
          FieldDescription.CreateStringField("InspectionNotes", 512);
        inspectionNotesFieldDescription.AliasName = "Inspection Notes";
    
        // Assemble a list of all of our field descriptions
        List<FieldDescription> fieldDescriptions = new List<FieldDescription>()
          {
            globalIDFieldDescription, objectIDFieldDescription, inspectionDateFieldDescription,
            inspectionResultsFieldDescription, inspectionNotesFieldDescription
          };
    
        // Create a TableDescription object to describe the table to create
        TableDescription tableDescription = new TableDescription("PoleInspection", fieldDescriptions);
    
        // Create a SchemaBuilder object
        SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
    
        // Add the creation of PoleInspection to our list of DDL tasks
        schemaBuilder.Create(tableDescription);
    
        // Execute the DDL
        bool success = schemaBuilder.Build();
    
        // Inspect error messages
        if (!success)
        {
          IReadOnlyList<string> errorMessages = schemaBuilder.ErrorMessages;
          //etc.
        }
      }
    }
    Creating a feature class
    {
      // Must be called within QueuedTask.Run
      void CreateFeatureClassSnippet(Geodatabase geodatabase, FeatureClass existingFeatureClass,
        SpatialReference spatialReference)
      {
        // Create a Cities feature class with the following fields
        // GlobalID
        // ObjectID
        // Name (string)
        // Population (integer)
    
        // This helper routine creates a FieldDescription for a GlobalID field with default values
        FieldDescription globalIDFieldDescription = FieldDescription.CreateGlobalIDField();
    
        // This helper routine creates a FieldDescription for an ObjectID field with default values
        FieldDescription objectIDFieldDescription = FieldDescription.CreateObjectIDField();
    
        // This helper routine creates a FieldDescription for a string field
        FieldDescription nameFieldDescription = FieldDescription.CreateStringField("Name", 255);
    
        // This helper routine creates a FieldDescription for an integer field
        FieldDescription populationFieldDescription = FieldDescription.CreateIntegerField("Population");
    
        // Assemble a list of all of our field descriptions
        List<FieldDescription> fieldDescriptions = new List<FieldDescription>()
            { globalIDFieldDescription, objectIDFieldDescription, nameFieldDescription, populationFieldDescription };
    
        // Create a ShapeDescription object
        ShapeDescription shapeDescription = new ShapeDescription(GeometryType.Point, spatialReference);
    
        // Alternatively, ShapeDescriptions can be created from another feature class.  In this case, the new feature class will inherit the same shape properties of the existing class
        ShapeDescription alternativeShapeDescription = new ShapeDescription(existingFeatureClass.GetDefinition());
    
        // Enable support for measure (M) value, if needed
        // shapeDescription.HasM = true;
    
        // Enable support for the vertical coordinate system (Z), if needed
        // shapeDescription.HasZ = true;
    
        // Create a FeatureClassDescription object to describe the feature class to create
        FeatureClassDescription featureClassDescription =
          new FeatureClassDescription("Cities", fieldDescriptions, shapeDescription);
    
        // Create a SchemaBuilder object
        SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
    
        // Add the creation of the Cities feature class to our list of DDL tasks
        schemaBuilder.Create(featureClassDescription);
    
        // Execute the DDL
        bool success = schemaBuilder.Build();
    
        // Inspect error messages
        if (!success)
        {
          IReadOnlyList<string> errorMessages = schemaBuilder.ErrorMessages;
          //etc.
        }
      }
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also