1

I have a layer in the TOC, with a query on a field. Then in layout view, I insert the table to the layout.

When I change the query the table does not update automatically. Then I double click on the table, and now it is changed manually.

How can I change the table in the layout dynamically when I change the query?

I am using ArcMap 10.8

enter image description here

3 Answers3

1

The dynamic table functionality that you seek is available in ArcGIS Pro as a Table Frame which you can see in Work with a table frame.

It is not available in ArcMap although, with a Production Mapping license, there is something akin to it, which is known as an Interactive Table. You can see them at Creating an interactive table.

Using ArcPy, you can use graphic and text elements to create pseudo-dynamic tables or table-like data frames with both ArcMap and ArcGIS Pro, but I consider that to be an advanced topic.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
  • As I understand the question, the table does update after a double click. And the TableFrame class holds a reference to the table it is displaying, so it should be possible for it to refresh itself. – Berend Sep 24 '23 at 20:12
  • The table is updated manually only when i double click on the table and just see the properties and click ok. – MAMDOUH ZALAKY Sep 24 '23 at 20:35
  • Unlike ArcGIS Pro, ArcPy with ArcMap does not provide a TableFrame class. – PolyGeo Sep 24 '23 at 21:50
  • But someone here told my this answer ...Using ArcPy, you can use graphic and text elements to create pseudo-dynamic tables or table-like data frames with both ArcMap and ArcGIS Pro, but I consider that to be an advanced topic. .... it means that i can use ArcMap to solve my problem through python script - ArcPy – MAMDOUH ZALAKY Sep 25 '23 at 04:46
  • 1
    They are not using a TableFrame class and therefore are not truly dynamic. – PolyGeo Sep 25 '23 at 06:49
  • Thank you for your answer – MAMDOUH ZALAKY Sep 25 '23 at 13:49
1

My preference is using 2nd dataframe, but this script will also work for basic tables. Just insert picture element and call it "myTABLE":

import matplotlib.pyplot as plt
import pandas as pd
# play with this
plt.figure(figsize=(8,1))
sourceFile = "f:/scratch/table.png"
tbl=arcpy.da.TableToNumPyArray("subc_5ha",("GRIDCODE","Shape_Area","SUBC_NAME","HA"))

df = pd.DataFrame(tbl) data = df.values plt.axis("off") plt.table(cellText=data, colLabels=df.columns, loc="center",fontsize=8) plt.savefig(sourceFile) plt.close() mxd = arcpy.mapping.MapDocument("CURRENT") for elm in arcpy.mapping.ListLayoutElements(mxd, "PICTURE_ELEMENT"): if elm.name == "myTABLE": try:elm.sourceImage = "" except: elm.sourceImage = sourceFile

Before: enter image description here

After:

enter image description here

Script converts table to png raster/image and replaces source of the picture in existing picture. To make it work you need to change 3 lines of code:

plt.figure(figsize=(8,1))

these are dimensions (width =8', height = 1') of your table image.

sourceFile = "f:/scratch/table.png"

this is name of the image on disk.

tbl=arcpy.da.TableToNumPyArray("subc_5ha",("GRIDCODE","Shape_Area","SUBC_NAME","HA"))

first parameter here (subc_5ha) is name of the layer in the current mxd table of content, followed by list of fields (GRIDCODE,..HA) that you'd like to show. No Shape field though.

Add picture element to your layout and name it 'myTABLE':

enter image description here

Attach script to custom tool or run it from Python window. Check if table fits into element. If not modify figsize in line 1.

UPDATE:

It seems that using text element and prettytable Python module produces much nicer output:

enter image description here

Unfortunately ArcGis 10.8 doesn't want to work directly with that module, so workflow involves call to tiny external script. If of interest I can post it.

FelixIP
  • 22,922
  • 3
  • 29
  • 61
  • Can you explain to me what should i do with more details. – MAMDOUH ZALAKY Sep 29 '23 at 10:47
  • That's a nifty way of creating a table using the matplotlib then getting ArcMap to embed it into a layout! Never used matplotlib but if others want to explore this approach here is a useful blog on creating tables and saving them as a graphic. – Hornbydd Sep 30 '23 at 16:29
  • It's a mighty tool especially in combination with DDP https://gis.stackexchange.com/questions/181390/accessing-graph-properties-in-arcpy – FelixIP Sep 30 '23 at 19:14
0

This seems to be a refresh issue of the table layout element. I don't know if this is by design.

I haven't found a way to automatically refresh the table, so you must do one of the following:

  • Click the Refresh button below the layout: Refresh button. But it looks as if this doesn't always work.
  • Right click on the table element, select Properties (Or just double click) and click OK or Apply
  • Close and reopen the mxd
  • There may be other options...
Berend
  • 4,737
  • 13
  • 27