官术网_书友最值得收藏!

Getting a list of tables

The arcpy.mapping module also has a ListTableViews() function that you can use to obtain a list of standalone tables that are contained within a map document. In this recipe, you will learn how to use the ListTableViews() function to create this list of tables.

Getting ready

In addition to providing the ability to generate a list of layers in a map document or data frame, the arcpy mapping module also provides a ListTableViews() function that generates a list of tables.

Note

ListTableViews() only works with map document files and the data frames contained within. Layer files do not have the capability of holding tables.

How to do it…

Follow these steps to learn how to get a list of standalone tables in a map document:

  1. Open c:\ArcpyBook\Ch3\Crime_Ch3.mxd with ArcMap.
  2. Click on the Python window button from the main ArcMap toolbar.
  3. Import the arcpy.mapping module:
    import arcpy.mapping as mapping
  4. Reference the currently active document (Crime_Ch3.mxd), and assign the reference to a variable:
    mxd = mapping.MapDocument("CURRENT")
  5. Generate a list of tables in the map document:
    for tableView in mapping.ListTableViews(mxd):
        print tableView.name
  6. Run the script to see the following output:.
    Crime2009Table
    

How it works…

The ListTableViews() function is very similar to the other list functions provided by arcpy.mapping. As was the case with ListLayers(), the ListTableViews() function accepts a reference to a map document (but not a layer file), along with an optional wildcard and data frame parameters. The output is a list of tables that can be iterated with a for loop.

主站蜘蛛池模板: 开远市| 甘孜| 锡林郭勒盟| 黑山县| 青浦区| 新巴尔虎左旗| 清丰县| 南阳市| 天镇县| 东乌| 红河县| 苏尼特左旗| 海晏县| 安乡县| 泰来县| 阿合奇县| 八宿县| 张家港市| 长葛市| 黄陵县| 文水县| 得荣县| 突泉县| 西峡县| 山东| 南城县| 青河县| 阿城市| 赤壁市| 柯坪县| 古田县| 武定县| 莫力| 桐城市| 大英县| 兴隆县| 巩义市| 望江县| 同江市| 钟山县| 苏尼特左旗|