arcpy.management.AddSubtype(in_table, subtype_code, subtype_description)
|
Name
|
Explanation
|
Data type
|
|
in_table
|
The feature class or table containing the subtype definition to be updated.
|
Table View
|
|
subtype_code
|
A unique integer value for the subtype to be added.
|
Long
|
|
subtype_description
|
A name (also known as description) of the subtype code.
|
String
|
Derived output
|
Name
|
Explanation
|
Data type
|
|
out_table
|
The updated table or feature class.
|
Table View
|
Code sample
AddSubtype example 1 (Python window)
The following Python window script demonstrates how to use the AddSubtype function in Immediate mode.
import arcpy
arcpy.env.workspace = "C:/data/Montgomery.gdb"
arcpy.management.SetSubtypeField("water/fittings", "TYPECODE")
arcpy.management.AddSubtype("water/fittings", "1", "Bend")
AddSubtype example 2 (stand-alone script)
The following stand-alone script demonstrates how to use the AddSubtype function as part of a workflow to add subtypes to a field.
# Name: ManageSubtypes.py
# Purpose: Create a subtype definition
# Import system modules
import arcpy
# Set the workspace (to avoid having to type in the full path to the data every time)
arcpy.env.workspace = "C:/data/Montgomery.gdb"
# Set local parameters
inFeatures = "water/fittings"
# Process: Set Subtype Field...
arcpy.management.SetSubtypeField(inFeatures, "TYPECODE")
# Process: Add Subtypes...
# Store all the suptype values in a dictionary with the subtype code as the
# "key" and the subtype name as the "value" (stypeDict[code])
stypeDict = {"0": "Unknown", "1": "Bend", "2": "Cap", "3": "Cross",
"4": "Coupling", "5": "Expansion joint", "6": "Offset",
"7": "Plug", "8": "Reducer", "9": "Saddle", "10": "Sleeve",
"11": "Tap", "12": "Tee", "13": "Weld", "14": "Riser"}
# use a for loop to cycle through the dictionary
for code in stypeDict:
arcpy.management.AddSubtype(inFeatures, code, stypeDict[code])
# Process: Set Default Subtype...
arcpy.management.SetDefaultSubtype(inFeatures, "4")
AddSubtype example 3 (stand-alone script)
The following script uses a try/except block to handle the error that is returned from the 'AddSubtype' function when a subtype code already exists for the field.
# Name: ManageSubtypes2.py
# Purpose: Add more subtype definitions
# Import system modules
import arcpy
# Set the workspace (to avoid having to type in the full path to the data every time)
arcpy.env.workspace = "C:/data/Montgomery.gdb"
# Set local parameters
inFeatures = "water/fittings"
# Define new subtypes to be added
# Store all the suptype values in a dictionary with the subtype code as the
# "key" and the subtype name as the "value" (stypeDict[code])
stypeDict = { "5": "Expansion joint", "6": "Offset", "7": "Plug",
"8": "Reducer", "9": "Saddle", "10": "Sleeve",
"11": "Tap", "12": "Tee", "13": "Weld", "14": "Riser"}
# Process: Add Subtypes...
# use a for loop to cycle through the dictionary
# use a try/except to catch errors from any subtypes that already exist on the field
for code in stypeDict:
try:
arcpy.management.AddSubtype(inFeatures, code, stypeDict[code])
except:
print(f"Skipping '{code}: {stypeDict[code]}' as it is already a subtype on the field.")