Table

Résumé

Provides access to basic table properties and methods.

Discussion

There are two ways tables can be referenced in a script for use in a project. To reference tables already in a project, use the listTables method on the Map Class. To reference tables directly from a workspace, use the Table function.

You may want to reference a table in a project using the listTables function because you may need to change a table's data source, its definition query, or even remove the table from the project using the removeTable method.

The Table function is useful for referencing new tables you want to add into a project. Once you have a reference to a new, external table source, you can add it to a Map using the addTable method.

Changing a tables's data source is a common requirement. There is a method and a property on the Layer object that help with this. For a more detailed discussion, parameter information, scenarios, and code samples, please refer to the Updating and fixing data sources help topic.

Propriétés

PropriétéExplicationType de données
connectionProperties
(Lecture seule)

Returns a table's data source connection information as a Python dictionary.

Dictionary
dataSource
(Lecture seule)

Returns the complete path for the table's data source. It includes the full workspace path and name of the dataset. For enterprise geodatabase tables, a string containing the table's connection information is returned.

Conseil :

Enterprise geodatabase tables in an ArcGIS Pro project do not retain the path to the database connection file (.sde) that was used to create the layer.

String
definitionQuery
(Lecture et écriture)

Provides the ability to get or set a tables's definition query.

String
isBroken
(Lecture seule)

Returns True if a table's data source is broken.

Boolean
metadata
(Lecture et écriture)

Get or set the table's Metadata class information. Note, setting metadata is dependent on the isReadOnly property value.

Metadata
name
(Lecture et écriture)

Provides the ability to set or get the name of a table the way it would appear in the table of contents. Spaces can be included.

String

Vue d’ensemble des méthodes

MéthodeExplication
getDefinition (cim_version)

Gets a table's CIM definition.

getSelectionSet ()

Returns a table's selection as a Python set of Object IDs.

setDefinition (definition_object)

Sets a table's CIM definition.

setSelectionSet ({oidList}, {method})

Sets a table's selection using a Python list of Object IDs.

updateConnectionProperties (current_connection_info, new_connection_info, {auto_update_joins_and_relates}, {validate}, {ignore_case})

Replaces connection properties using a dictionary or a path to a workspace.

Méthodes

getDefinition (cim_version)
ParamètreExplicationType de données
cim_version

A string that represents the major version of the CIM.

String

CIM-level access to additional object properties was introduced at version 2.4. Esri follows the semantic versioning specification. This means that until the next major release—for example, 3.0—when breaking API changes are allowed, the value to be used with cim_version is V2. Once 3.0 is released, a new V3 option will become available. This gives Python script authors control over the CIM version that will be used during execution if there is a possibility that breaking changes may be introduced in the new version.

For more information about working with the CIM and samples, see Python CIM Access.

getSelectionSet ()
Valeur renvoyée
Type de donnéesExplication
List

Returns a table's selection as a Python set of Object IDs.

Provides an easy way to retrieve the table's current selection.

setDefinition (definition_object)
ParamètreExplicationType de données
definition_object

A modified CIM definition object originally retrieved using getDefinition.

Object

For more information about working with the CIM and samples, see Python CIM Access.

setSelectionSet ({oidList}, {method})
ParamètreExplicationType de données
oidList
[oidList,...]

A Python list of Object IDs to use along with the appropriate selection method.

(La valeur par défaut est None)

List
method

A string that specifies which selection method to use.

  • NEWCreates a new record selection from the oidList.
  • DIFFERENCESelects the records that are not in the current selection but are in the oidList.
  • INTERSECTSelects the records that are in the current selection and the oidList.
  • SYMDIFFERENCESelects the records that are in the current selection or the oidList but not both.
  • UNIONSelects all the records in both the current selection and those in the oidList.

(La valeur par défaut est NEW)

String

This method provides an easy way to manage a table's selection. To clear the selection, use the NEW selection method with an empty list or don't set any parameters. Python lists are used for the oidList, but sets get returned from the getSelectionSet method on the Table object.

updateConnectionProperties (current_connection_info, new_connection_info, {auto_update_joins_and_relates}, {validate}, {ignore_case})
ParamètreExplicationType de données
current_connection_info

A string that represents the workspace path or a Python dictionary that contains connection properties to the source you want to update.

String
new_connection_info

A string that represents the workspace path or a Python dictionary that contains connection properties with the new source information.

String
auto_update_joins_and_relates

If set to True, the updateConnectionProperties method will also update the connections for associated joins or relates.

(La valeur par défaut est True)

Boolean
validate

If set to True, the connection properties will only be updated if the new_connection_info value is a valid connection. If it is not valid, the connection will not be replaced. If set to False, the method will set all connections to match the new_connection_info, regardless of a valid match. In this case, if a match does not exist, then the data sources would be broken.

(La valeur par défaut est True)

Boolean
ignore_case

Determines whether searches will be case sensitive or not. By default, queries are case sensitive. To perform case-insensitive queries, set ignore_case to True.

(La valeur par défaut est False)

Boolean

For more detailed discussion, parameter information, scenarios, and code samples, refer to the Updating and fixing data sources help topic.

Exemple de code

Table example 1

The following script will print the stand-alone table names that have a broken data source for all tables in all maps.

import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Projects\YosemiteNP\Yosemite.aprx")
for m in aprx.listMaps():
    for tbl in m.listTables():
        if tbl.isBroken:
            print(f"Table: {tbl.name} is broken in map: {m.name}")
del aprx
Table example 2

The following script will add a table from a file geodatabase into a map.

import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Projects\YosemiteNP\Yosemite.aprx")
addTab = arcpy.mp.Table(r"C:\Projects\YosemiteNP\Data_Vector\YosemiteData.gdb\NHDFCode")
m = aprx.listMaps("Yose*")[0]
m.addTable(addTab)
del aprx