Sheet Set Detection#

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.sheet.set.detection import SheetSet, detect_sets_by_subdivision_lines, find_set_symbols

_DATA_DIR = Path("data/json")
_drawing_sets = Drawing.from_json(str(_DATA_DIR / "sheet_with_sets_1.json"))
featured_drawing = FeaturedDrawing(_drawing_sets, language_configs=[DEFAULT_FRENCH_CONFIG, DEFAULT_ENGLISH_CONFIG])
sheet = _drawing_sets.sheets[0]
featured_sheet = featured_drawing.sheets[0]
sets = detect_sets_by_subdivision_lines(sheet)
sheet_set = sets[0] if sets else None
featured_sheet.plot_data_sets().plot()

The sheet set detection module identifies named rectangular regions (called sets) within a technical drawing sheet. A set corresponds to, either the complete area of a sheet, or a sub-area of the sheet delimited by subdivision lines and identified by a SET marker symbol.

Purpose#

Some technical drawings pack multiple independent assemblies or parts onto a single sheet, separated by visible subdivision lines. Each region is labeled with a SET marker symbol (e.g., “000”, “001”) that names that portion of the sheet.

This module provides:

  • SheetSet dataclass: Represents a named rectangular region with spatial query methods

  • Automatic detection: Finds subdivision lines and SET markers to create SheetSet instances

  • View-to-set mapping: Determines which views belong to which set

  • Visualization: SheetSetsSketcher for color-coded region overlays

These capabilities are useful for:

  • Analyzing multi-part sheets where each set has its own views

  • Filtering views by set for targeted processing

  • Validating that the correct annotations appear in each set region

Overview#

The detection algorithm in detect_sets_by_subdivision_lines() follows these steps:

  1. Extract the content zone from the sheet’s background view

  2. Search for subdivision lines — horizontal or vertical line segments spanning at least 80% of the content zone’s width or height

  3. Split the content zone into candidate rectangular regions using the subdivision lines

  4. Find all SET marker symbols (frame.entity_type == "SET") on the sheet

  5. For each candidate region, match SET symbols whose center falls inside the region

  6. Create a SheetSet for each matched symbol, named from the symbol’s text content

If no subdivision lines are found, the entire content zone is treated as a single candidate region, which is useful for sheets that have SET markers without explicit subdivision lines.

Visualization Example#

The following interactive visualization shows a sheet with two detected sets “001” and “000”, highlighted with color-coded overlays produced by SheetSetsSketcher:

Note

Multiple SET symbols per region

A single rectangular region can contain more than one SET marker symbol. In that case, one SheetSet is created per symbol, all sharing the same bounding_rectangle. When visualized, this produces overlapping colored rectangles in the same area — one per set. The following visualization illustrates this case with 3 sets (003, 004, 005) sharing the same region:

Source: sheet_with_sets_3.json, Sheet 2

SheetSet Dataclass#

SheetSet is a dataclass representing one named region:

from drawing_tools.sheet.set.detection import SheetSet

Attributes:

  • name (str): The set identifier (e.g., “000”, “001”)

  • bounding_rectangle (BoundingRectangle): The rectangular boundary

  • symbol (Symbol | None): The SET marker symbol that identifies this set

Spatial Query Methods#

# Check if a point is inside the set
sheet_set.contains_point(point_2d)  # -> bool

# Check if a rectangle is fully inside the set
sheet_set.fully_contains_rectangle(rectangle)  # -> bool

# Check if an entity's center is inside the set
sheet_set.contains_entity(entity)  # -> bool

Detection Functions#

detect_sets_by_subdivision_lines#

Main detection function. Analyzes the sheet’s background view to find subdivision lines and SET markers:

from drawing_tools.sheet.set.detection import detect_sets_by_subdivision_lines

sets = detect_sets_by_subdivision_lines(sheet)
# sets: list[SheetSet]

Parameters:

  • sheet (Sheet): The sheet to analyze

  • min_length_ratio (float, default 0.8): Minimum fraction of the content dimension a line must span to qualify as a subdivision line

find_set_symbols#

Public helper that finds all SET marker symbols on a sheet:

from drawing_tools.sheet.set.detection import find_set_symbols

symbols = find_set_symbols(sheet)
print(f"Found {len(symbols)} SET symbols")

FeaturedSheet Integration#

FeaturedSheet exposes set detection through convenient properties and methods. Detection is lazy-cached: the first access to sets triggers the detection algorithm, and subsequent accesses return the cached result.

Properties#

  • setslist[SheetSet]: All detected sets (lazy-cached)

  • has_setsbool: Whether the sheet has any detected sets

  • views_by_setdict[str, list[FeaturedView]]: Views organized by set name

Methods#

  • get_set_for_view(view)SheetSet | None: Find which set a view belongs to. Returns None if the view spans multiple sets.

  • get_views_in_set(sheet_set)list[FeaturedView]: Get all views fully contained within a given set. Views that span multiple sets are excluded.

Usage Examples#

Basic Detection#

from pathlib import Path
from dessia_drawing.core import Drawing
from drawing_tools import FeaturedDrawing
from drawing_tools.config.default_language_configs import DEFAULT_FRENCH_CONFIG, DEFAULT_ENGLISH_CONFIG

drawing = Drawing.from_json(filepath=Path("drawing.json"))
featured_drawing = FeaturedDrawing(
    drawing=drawing,
    language_configs=[DEFAULT_FRENCH_CONFIG, DEFAULT_ENGLISH_CONFIG]
)

for sheet in featured_drawing.sheets:
    print(f"Sheet: {sheet.name}")
    print(f"Has sets: {sheet.has_sets}")
    print(f"Sets count: {len(sheet.sets)}")

    for sheet_set in sheet.sets:
        br = sheet_set.bounding_rectangle
        print(f"\nSet '{sheet_set.name}':")
        print(f"  Bounds: x=[{br.xmin:.1f}, {br.xmax:.1f}], y=[{br.ymin:.1f}, {br.ymax:.1f}]")

Querying Views by Set#

for sheet in featured_drawing.sheets:
    # Get views organized by set
    for set_name, views in sheet.views_by_set.items():
        print(f"Set '{set_name}': {[v.name for v in views]}")

    # Find which set each view belongs to
    for view in sheet.views:
        found_set = sheet.get_set_for_view(view)
        if found_set:
            print(f"  {view.name} -> Set '{found_set.name}'")
        else:
            print(f"  {view.name} -> spans multiple sets")

Finding SET Symbols#

from drawing_tools.sheet.set.detection import find_set_symbols

for sheet in featured_drawing.sheets:
    symbols = find_set_symbols(sheet)
    print(f"Found {len(symbols)} SET symbols:")
    for symbol in symbols:
        print(f"  - '{symbol.get_text_content().strip()}'")

Script#

The script scripts/sheet_sets_detector.py demonstrates the full detection pipeline including SET symbol discovery, set detection, view-to-set mapping, and visualization with SheetSetsSketcher.

Visualization#

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

featured_sheet.plot_data_sets().plot()

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

See Also#