How Patent-Disclosure-Skill Processes STEP/STP Files for CadQuery Extraction
The patent-disclosure-skill processes STEP/STP files through an opt-in pipeline that uses CadQuery and OpenCASCADE to extract assembly trees, render multi-view SVG projections, and convert them to PNGs for patent documentation generation.
The handsomestWei/patent-disclosure-skill repository treats STEP (.step / .stp) files as its primary neutral 3-D exchange format for CAD data ingestion. When handling STEP/STP files for CadQuery extraction, the skill coordinates three specialized components—file classification, STEP parsing with view generation, and runtime environment management—to transform geometric models into visual assets suitable for patent disclosure drafts.
STEP File Processing Architecture
The system delegates responsibilities across three Python modules that handle detection, parsing, and execution environment setup.
File Classification and Detection
The cad_formats.py module provides the entry point for STEP file handling. According to the source code in skills/patent-disclosure/tools/cad_formats.py, the functions is_step, classify_path, and recommend_action determine whether STEP files exist in a case directory and whether to prompt the user for parsing.
When cad_scan.py scans a directory, it calls cad_formats.iter_classified to collect STEP files. If any are found, recommend_action returns "ask_enable_step_parse", triggering a confirmation prompt before processing begins.
Core Extraction Engine
The step_to_views.py module contains the primary logic for STEP/STP file processing. Key functions include extract_assembly_tree for hierarchical assembly analysis, render_views for generating orthogonal projections, and build_figure_plan_seed and build_structure_seed for creating metadata YAML files that describe the extracted geometry.
This module attempts to use the OpenCASCADE XCAF API (via the OCP package) as its preferred parsing path, falling back to standard CadQuery importers if XCAF is unavailable.
Runtime Environment Management
Because CadQuery requires specific native dependencies, the skill isolates the CAD environment using bootstrap_cad_venv.py and cad_venv.py. The CLI wrapper run_step_to_views.py ensures the cad-env virtual environment is active before invoking the extraction pipeline, aborting with installation hints if CadQuery cannot be imported.
The STEP-to-Views Pipeline
The workflow follows a strict eight-stage process from file discovery to metadata generation.
Discovery and User Opt-In
STEP parsing is disabled by default to prevent accidental processing of large CAD datasets. Users must explicitly enable extraction using either the command-line flag --enable-step-parse or by setting the environment variable PATENT_SKILL_STEP_PARSE=1. The function step_to_views.parse_enabled checks both conditions before proceeding.
Assembly Tree Extraction with XCAF
The extract_assembly_tree function in step_to_views.py implements a dual-path strategy:
- Preferred path: Uses
OCP(OpenCASCADE Python bindings) to read the STEP file via the XCAF API, enumerate free shapes, and build a hierarchical list of parts with proper assembly relationships. - Fallback path: If XCAF is unavailable, the script imports the STEP file using
cadquery.importers.importStepand counts solid bodies via_fallback_solids_tree, providing a flat solid count rather than a tree structure.
Multi-View Rendering and Rasterization
Once the geometry is loaded, render_views generates visual documentation by iterating over DEFAULT_VIEWS (iso, front, top, right). For each view:
- The function calls
cq.exporters.export()withExportTypes.SVGand projection parameters to create vector graphics. - It attempts PNG rasterization using cairosvg via
_svg_to_png_cairo. - If Cairo is missing, the SVG remains without a PNG counterpart until the browser fallback stage.
The _rasterize_svgs_browser function launches svg_screenshot.py via Playwright to convert any remaining SVGs to PNGs using a headless browser when native rasterization fails.
Metadata Generation for Patent Drafts
After rendering, the pipeline produces two YAML seed files:
- Figure Plan:
build_figure_plan_seedcreates entries withkind: "cad"for each view, explicitly marking them as material only (never line-art). - Structure Schema:
build_structure_seedconverts the assembly tree into a hierarchical description, flagging uncertainties and noting the parsing method used (xcaforsolid_count).
Outputs are written to the user-specified directory (e.g., outputs/case/cad_views).
Code Examples
Running the STEP-to-Views Pipeline
# Initialize the CadQuery virtual environment (one-time setup)
python tools/bootstrap_cad_venv.py
# Parse a STEP file and generate multi-view assets
python tools/run_step_to_views.py \
--enable-step-parse \
-i model.step \
-o outputs/case/cad_views
Programmatic API Usage
from pathlib import Path
from skills.patent_disclosure.tools.step_to_views import render_views, extract_assembly_tree
step_file = Path("model.step")
out_dir = Path("outputs/cad_views")
# Generate SVG and PNG projections
views = render_views(step_file, out_dir)
# Extract hierarchical assembly description
assembly = extract_assembly_tree(step_file)
Classifying Files Before Parsing
from skills.patent_disclosure.tools.cad_formats import iter_classified, recommend_action
result = iter_classified(["./case"], recursive=True)
action = recommend_action(
result["step"],
result["native_cad"],
result["iges"]
)
# Returns "ask_enable_step_parse" if STEP files are present
print(action)
Summary
- STEP/STP files are the only neutral 3-D format the skill parses directly, as implemented in
handsomestWei/patent-disclosure-skill. - Parsing requires explicit opt-in via
--enable-step-parseor thePATENT_SKILL_STEP_PARSE=1environment variable. - The
step_to_views.pymodule uses OpenCASCADE XCAF for assembly tree extraction, falling back to basic CadQuery solid counting if necessary. - The pipeline generates orthogonal SVG views (iso, front, top, right) and converts them to PNGs using Cairo or a Playwright-based browser fallback.
- Output includes both visual assets and YAML metadata seeds (
figure_planandstructure) for patent documentation workflows.
Frequently Asked Questions
What CAD formats does patent-disclosure-skill support besides STEP/STP?
According to the source code in cad_formats.py, the system can detect and classify various CAD formats, but STEP is the only neutral format processed for CadQuery extraction. Native proprietary formats are acknowledged during classification but require conversion to STEP before the pipeline can process them.
Why is STEP parsing disabled by default in the skill?
STEP parsing is computationally expensive and requires a heavyweight virtual environment with native OpenCASCADE dependencies. Disabling it by default—controlled by parse_enabled checking for flags or environment variables—prevents accidental resource consumption when scanning case directories that may contain large or numerous CAD files.
How does the tool handle large STEP assemblies?
The tool handles large assemblies through hierarchical extraction using the XCAF API in extract_assembly_tree, which preserves assembly structure rather than flattening the geometry. If memory constraints occur, the system falls back to _fallback_solids_tree, which simply counts solids without building a full hierarchy, reducing memory overhead at the cost of structural detail.
What dependencies are required to run the CadQuery extraction pipeline?
The pipeline requires CadQuery and its native dependencies (OpenCASCADE), isolated within a virtual environment managed by bootstrap_cad_venv.py. For PNG generation, cairosvg is preferred, but the system can fall back to Playwright (via svg_screenshot.py) if Cairo is unavailable. The host Python environment must support subprocess execution to manage the isolated cad-env.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →