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
-
This page may help?Hornbydd– Hornbydd2023年09月23日 13:28:30 +00:00Commented Sep 23, 2023 at 13:28
-
Thank you for your answer ..... but this documention help doesn't fix my problem .MAMDOUH ZALAKY– MAMDOUH ZALAKY2023年09月23日 13:53:23 +00:00Commented Sep 23, 2023 at 13:53
-
Does it update if you click on the refresh button below to the layout?Berend– Berend2023年09月24日 20:18:45 +00:00Commented Sep 24, 2023 at 20:18
-
No it doesn't , the table is updated manually only when i double click on the table and just see the properties and click ok.MAMDOUH ZALAKY– MAMDOUH ZALAKY2023年09月24日 20:34:05 +00:00Commented Sep 24, 2023 at 20:34
3 Answers 3
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.
-
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– Berend2023年09月24日 20:12:48 +00:00Commented Sep 24, 2023 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– MAMDOUH ZALAKY2023年09月24日 20:35:41 +00:00Commented Sep 24, 2023 at 20:35
-
Unlike ArcGIS Pro, ArcPy with ArcMap does not provide a TableFrame class.2023年09月24日 21:50:27 +00:00Commented Sep 24, 2023 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 - ArcPyMAMDOUH ZALAKY– MAMDOUH ZALAKY2023年09月25日 04:46:08 +00:00Commented Sep 25, 2023 at 4:46
-
1They are not using a TableFrame class and therefore are not truly dynamic.2023年09月25日 06:49:04 +00:00Commented Sep 25, 2023 at 6:49
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:
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':
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:
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.
-
Can you explain to me what should i do with more details.MAMDOUH ZALAKY– MAMDOUH ZALAKY2023年09月29日 10:47:09 +00:00Commented Sep 29, 2023 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– Hornbydd2023年09月30日 16:29:59 +00:00Commented Sep 30, 2023 at 16:29
-
It's a mighty tool especially in combination with DDP gis.stackexchange.com/questions/181390/…FelixIP– FelixIP2023年09月30日 19:14:07 +00:00Commented Sep 30, 2023 at 19:14
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...
-
The same result for me , nothing change the table automatically when i change the query for the layer.MAMDOUH ZALAKY– MAMDOUH ZALAKY2023年09月26日 16:14:54 +00:00Commented Sep 26, 2023 at 16:14
Explore related questions
See similar questions with these tags.