Table Navigation#

from pathlib import Path
from dessia_drawing.core import Drawing
from drawing_tools.config.default_language_configs import DEFAULT_ENGLISH_CONFIG, DEFAULT_FRENCH_CONFIG
from drawing_tools.featured_drawing import FeaturedDrawing
from drawing_tools.table.detection import SheetTableDetector

_DATA_DIR = Path("data/json")
drawing = Drawing.from_json(str(_DATA_DIR / "2902060102_--A_DEF01_LH SUPPORT ACCUMULATOR ASSEMBLY.json"))
featured_drawing = FeaturedDrawing(drawing, language_configs=[DEFAULT_FRENCH_CONFIG, DEFAULT_ENGLISH_CONFIG])
featured_sheet = featured_drawing.sheets[1]
detector = SheetTableDetector(sheet=featured_sheet.sheet)
tables_dict = detector.detect_all_tables()
table = next((t for tables in tables_dict.values() for t in tables), None)
featured_sheet.plot_data_tables().plot()

Drawing Tools provides table detection and extraction capabilities for technical drawings. This guide explains how to detect, analyze, and extract data from tables.

Overview#

Technical drawings often contain tables such as:

  • Title blocks with drawing metadata

  • Bills of Materials (BOM)

  • Revision tables

  • Custom data tables

Drawing Tools can automatically detect these tables from the raw line geometry and extract their structure and content.

The following visualization is produced by featured_sheet.plot_data_tables(), which highlights each detected table with a colored rectangle and labels the title block in magenta. This method is also available on FeaturedDrawing to visualize all sheets at once.

Source: 2902060102_–A_DEF01_LH SUPPORT ACCUMULATOR ASSEMBLY.json, Sheet 1

See also

For a complete working example, see scripts/scripts_tables.py.

For a detailed description of the detection pipeline internals, see Table Detection Pipeline.

Quick Start#

from dessia_drawing.core import Drawing
from drawing_tools.table.detection import SheetTableDetector

drawing = Drawing.from_json("path/to/drawing.json")
sheet = drawing.sheets[0]

detector = SheetTableDetector(sheet=sheet)

# Detect all tables across all views
tables_dict = detector.detect_all_tables()

for view_idx, tables in tables_dict.items():
    for table in tables:
        print(f"View {view_idx}: {table.nb_rows}r x {table.nb_cols}c")

# Detect the title block specifically
title_block = detector.detect_title_block()

Note

SheetTableDetector accepts both dessia_drawing.Sheet and FeaturedSheet objects.

Working with Detected Tables#

Table Properties#

# Table dimensions
print(f"Rows: {table.nb_rows}")
print(f"Columns: {table.nb_cols}")
print(f"Cells: {table.nb_cells}")

# Access all cells
for cell in table.cells:
    print(f"Cell ({cell.row_id}, {cell.col_id}): {cell.get_text_content()}")

TableCell vs GridCell#

Tables have two cell concepts:

  • GridCell: The basic grid unit (single row/column intersection) — see Fig. 4 below

  • TableCell: A logical cell that may span multiple grid cells (merged cells) — see Fig. 3 below

# Get a table cell (may span multiple grid cells)
table_cell = table.get_table_cell_at(row_index=1, column_index=1)

if table_cell:
    print(f"Content: {table_cell.get_text_content()}")
    print(f"Combined text: {table_cell.get_combined_text()}")
    print(f"Row span: {table_cell.row_span}")
    print(f"Column span: {table_cell.column_span}")

# Get the underlying grid cell
grid_cell = table.get_grid_cell_at(row_index=1, column_index=1)

Accessing Cell Content#

# All content objects from all cells
all_content = table.get_all_content()

# Iterate over cells
for cell in table.cells:
    content = cell.get_text_content() or "(empty)"
    print(f"({cell.row_id}, {cell.col_id}): {content}")

# Search for specific text
cells = table.find_table_cells_with_text("DIMENSION", case_sensitive=False)
for cell in cells:
    print(f"Found at ({cell.row_id}, {cell.col_id})")

Working with Title Blocks#

title_block = detector.detect_title_block()
table = title_block.parent_table  # DetectedTable with all methods above

Visualization#

# Basic visualization
table.plot_data()
Fig. 1 - Basic table visualization with plot_data()
# Without color legend
table.plot_data(color_legend=False)
Fig. 2 - Table visualization without color legend
# Detailed view with cell boundaries
table.plot_data(legend=False, detailed=True)
Fig. 3 - Detailed view showing TableCell boundaries
# Visualize the underlying grid
table.grid.plot_data(extra_primitives=[])
Fig. 4 - GridCell structure visualization

Visualization#

Use the @plot_data_view method on FeaturedSheet to visualize detected tables:

# All detected tables with title block highlighted
featured_sheet.plot_data_tables().plot()

This method is also available on FeaturedDrawing to visualize all sheets at once. See Display & Report Methods for more interactive examples.