TableView
Récapitulatif
Provides access to basic table properties
Discussion
The TableView object references a stand-alone table within the ArcMap table of contents and provides access to a table's name, data source, and definition query properties. The ListTableViews function returns a Python list of TableView objects. It is necessary to then iterate through each item in the list or specify an index number to reference a specific TableView object.
Tables can be searched within an entire map document or within a specific data frame. Wildcards can also be used to limit the search.
A definition query will not work for all workspaces. It is important to use the correct SQL syntax when working with different workspaces. For example, file geodatabases and shapefiles have double quotes around a field name (for example, "field_name"), personal geodatabases have brackets (for example, [field_name]), and SDE connections don't have any special characters (for example, field_name). For more information on updating workspaces and data sources in a map document or layer file, please refer to the Updating and Fixing Data Sources with arcpy.mapping help topic.
Propriétés
Propriété | Explication | Type de données |
datasetName (Lecture seule) |
Returns the name of the table's dataset the way it appears in the workspace, not in the table of contents. | String |
dataSource (Lecture seule) |
Returns table's data source path. | String |
definitionQuery (Lecture seule) |
Provides the ability to get or set a tables's definition query. | String |
name (Lecture et écriture) |
Provides the ability to set or get the name of a table the way it would appear in the ArcMap table of contents. Spaces can be included. | String |
workspacePath (Lecture seule) |
Returns a path to the table's workspace or connection file. | String |
Vue d'ensemble des méthodes
Méthode | Explication |
findAndReplaceWorkspacePath (find_workspace_path, replace_workspace_path, {validate}) |
Replaces a table's workspace with a new workspace path |
replaceDataSource (workspace_path, workspace_type, dataset_name, {validate}) |
Replaces a table's data source in a map document (.mxd); also provides the ability to switch workspace types (for example, replace a file geodatabase workspace with an SDE workspace). |
Méthodes
Paramètre | Explication | Type de données |
find_workspace_path |
A string that represents the workspace path or connection file you want to find. If an empty string is passed, then all workspace paths will be replaced with the replace_workspace_path parameter depending on the value of the validate parameter. | String |
replace_workspace_path |
A string that represents the workspace path or connection file you want to use to replace. | String |
validate | If set to True, the workspace will only be updated if the replace_workspace_path value is a valid workspace. If it is not valid, the workspace will not be replaced. If set to False, the method will set the workspace to match the replace_workspace_path, regardless of a valid match. In this case, if a match does not exist, then the table's data source would be broken. (La valeur par défaut est True) | Boolean |
For more detailed discussion, parameter information, scenarios, and code samples, please refer to the Updating and fixing data sources help topic.
Paramètre | Explication | Type de données |
workspace_path |
A string that includes the workspace path to the new data or connection file. | String |
workspace_type | A string keyword that represents the workspace type of the new data.
| String |
dataset_name | A string that represents the name of the table the way it appears in the new workspace (not the name of the table in the table of contents). | String |
validate | If set to True, a workspace will only be updated if the workspace_path value is a valid workspace. If it is not valid, the workspace will not be replaced. If set to False, the method will set the workspace to match the workspace_path, regardless of a valid match. In this case, if a match does not exist, then the data source would be broken. (La valeur par défaut est True) | Boolean |
For more detailed discussion, parameter information, scenarios, and code samples, please refer to the Updating and Fixing Data Sources help topic.
Exemple de code
The following script will find a table called Customers in a data frame named Transportation and will set its definition query.
import arcpy mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd") df = arcpy.mapping.ListDataFrames(mxd, "Transportation")[0] for table in arcpy.mapping.ListTableViews(mxd, "", df): if table.name.lower() == "trafficaccidents": table.definitionQuery = "\"age\" >= 18" mxd.save() del mxd