Calculates a field within a Feature Layer or Table View to a given expression. The output is written to a new Feature Class or Table. (This tool was written because the CalculateField field method does not allow you to edit a table that has a Join.)
When the input is a Feature Layer, it can reference either a shapefile or geodatabase. When the input is a Table View, it can reference either a dBase table or a geodatabase table.
The output dataset must be of the same data type as the dataset referenced by the input Feature Layer or Table View.
This tool is susceptible to failure due to a SCHEMA LOCK, especially when the datasets are geodatabases. If the datasets are geodatabases, the tool will fail if a schema lock is in place on the database. First remove all layers from ArcMap that reference the database. Next delete the schema lock file if it still exists. In the case of a personal geodatabase the schema lock file bears the same name as the database, but has a .ldb extension. If the schema lock file can not be deleted, exit ArcMap. Again try to delete it. (You may have to wait up to a minute before the file can be deleted.) If all else fails, reboot the computer, and try to delete the schema lock file.
CalculateField_Join <Layer_File> <Field_Name> <Expression> <Output_Feature_Class>
Parameters
| Expression | Explanation |
|---|---|
| <Layer_File> | The input Feature Layer or Table View.
|
| <Field_Name> | The field in the input table whose values will be calculated using the Expression. |
| <Expression> | The expression used to calculate new values for the field specified by the Field Name.
|
| <Output_Feature_Class> | The name for the output feature class or table.
|
Command Line Example
workspace c:\workspace\facts Set c:\workspace\facts into workspace CalculateField_Join activity_region.lyr activity_region.polyno [activity_poly_rxp.polyno] activity_region2.shp Executing (CalculateField_Join_1): CalculateField_Join "C:\workspace\facts\activity_region.lyr" activity_region.polyno [activity_poly_rxp.polyno] activity_region2.shp Start Time: Sun May 28 18:16:45 2006 Running script CalculateField_Join... Completed script CalculateField_Join... Executed (CalculateField_Join_1) successfully. End Time: Sun May 28 18:17:13 2006 (Elapsed Time: 28.00 secs)
CalculateField_Join (Layer_File, Field_Name, Expression, Output_Feature_Class)
Parameters
| Expression | Explanation |
|---|---|
| Layer File (Required) | The input Feature Layer or Table View.
|
| Field Name (Required) | The field in the input table whose values will be calculated using the Expression. |
| Expression (Required) | The expression used to calculate new values for the field specified by the Field Name.
|
| Output Feature Class (Required) | The name for the output feature class or table.
|
Script Example
# Import modules.
import sys, string, os, win32com.client
# Create the Geoprocessor object
gp = win32com.client.Dispatch('esriGeoprocessing.GpDispatch.1')
# Load DV Region toolbox.
gp.AddToolbox('C:/Documents and Settings/dchatfie/Application Data/ESRI/ArcToolbox/My Toolboxes/' + \
'DV Data Management Tools.tbx')
# Set workspace.
gp.workspace = 'c:/workspace/facts'
# Add polyno field to input region feature class
gp.addfield('activity_region.shp', 'polyno', 'long', 9, 0, 9)
# Join input region feature class with RXP table.
gp.makefeaturelayer('activity_region.shp', 'lyr')
gp.addjoin('lyr', 'objectid', 'activity_poly_rxp.dbf', 'subclassno')
# Calculate polyno field using Join to RXP table.
gp.calculatefield_join('lyr', 'activity_region.polyno', '[activity_poly_rxp.polyno]', 'activity_region2.shp')
# Remove Join.
gp.removejoin('lyr', 'activity_poly_rxp')