Select to view content in your preferred language

ArcGIS 10.2 May I open the attribute table (only the selected features) using arcpy?

3372
3
Jump to solution
05-04-2014 07:27 PM
LiYao
by
Deactivated User
Hi everybody,

I want to open the attribute table (only the selected features) using python, is it possible? If possible, which function should I use?
Thanks.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
benberman
Regular Contributor
Thank you eibenm,
In fact, I am not intend to do after the attribute table is opened.
As user's request, I create a new arctoolbox with several script tools using python. After entering the searching criteria, a table with the selected features data need to displayed on the map in a table format. I am not sure whether I should try to open the attribute table or I should create a table on this. Any body have experience on this?
thanks


Sounds like what you are after is the TableView class in mapping module

http://resources.arcgis.com/en/help/main/10.2/index.html#/TableView/00s300000017000000/

example

import arcpy mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd") df = arcpy.mapping.ListDataFrames(mxd, "Transportation")[0] accidentsTable = arcpy.mapping.TableView(r"C:\Project\Data\Transportation.gdb\Accidents") arcpy.mapping.AddTableView(df, accidentsTable) mxd.saveACopy(r"C:\Project\Project2.mxd") del mxd, accidentsTable

View solution in original post

0 Kudos
3 Replies
MattEiben
Deactivated User
What you looking to do after the attribute table is opened?

As far as I know, there is no way to open up the graphic attribute table within ArcMap using Python.  If you're looking to search though the data, what you're looking for is a Search Cursor.

The general format looks something like this.
SearchCursor (in_table, field_names, {where_clause})

An example of how you use it:

fields = ["ID","Name","Address","City","Zip","Distance"]
query = "\"Distance\" > 3"

with arcpy.da.SearchCursor("FeatureLayer", fields, query) as cursor:
    for row in cursor:
        print row


The cursor object treats each line of your attribute table as a Python list.  So when each row is printed out, you'll see it as a list.

If you can be more specific what you're trying to do, we can try to help with giving you some more direction.
0 Kudos
LiYao
by
Deactivated User
Thank you eibenm,
In fact, I am not intend to do after the attribute table is opened.
As user's request, I create a new arctoolbox with several script tools using python. After entering the searching criteria, a table with the selected features data need to displayed on the map in a table format. I am not sure whether I should try to open the attribute table or I should create a table on this. Any body have experience on this?
thanks
0 Kudos
benberman
Regular Contributor
Thank you eibenm,
In fact, I am not intend to do after the attribute table is opened.
As user's request, I create a new arctoolbox with several script tools using python. After entering the searching criteria, a table with the selected features data need to displayed on the map in a table format. I am not sure whether I should try to open the attribute table or I should create a table on this. Any body have experience on this?
thanks


Sounds like what you are after is the TableView class in mapping module

http://resources.arcgis.com/en/help/main/10.2/index.html#/TableView/00s300000017000000/

example

import arcpy mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd") df = arcpy.mapping.ListDataFrames(mxd, "Transportation")[0] accidentsTable = arcpy.mapping.TableView(r"C:\Project\Data\Transportation.gdb\Accidents") arcpy.mapping.AddTableView(df, accidentsTable) mxd.saveACopy(r"C:\Project\Project2.mxd") del mxd, accidentsTable
0 Kudos