Skip to main content

Headless screenshot generator for three-cad-viewer

Project description

tcv-screenshots

Headless screenshot generator for three-cad-viewer. Render 3D CAD models to PNG screenshots.

Supported Platforms

  • Linux (Intel, ARM)
  • Windows (Intel)
  • macOS (Intel, Apple Silicon)

Installation

pip install tcv-screenshots
playwright install chromium

If you use build123d for creating 3D objects, build123d neeeds to be installed, similar for CadQuery.

Usage

# Single file (output to current directory)
python -m tcv_screenshots -f example.py

# Single file with output folder
python -m tcv_screenshots -f example.py -o screenshots

# Directory of examples (requires -o)
python -m tcv_screenshots -d examples -o screenshots

Options:

  • -f, --file FILE - Single Python example file to process
  • -d, --directory DIR - Directory containing Python example files (requires -o)
  • -o, --output-folder DIR - Output directory for PNG screenshots
  • --no-headless - Show browser window (for debugging)
  • --pause - Pause before each screenshot (for debugging)
  • --debug MODELS_DIR - Save JSON model files to directory (for debugging)

Writing Examples

Create a Python file with a main() function that uses save_model and returns get_saved_models():

from build123d import *

model = Box(10, 20, 30)

def main():
    from tcv_screenshots import save_model, get_saved_models

    save_model(model, "box", {"cadWidth": 800, "height": 600})
    return get_saved_models()

Multiple Models per Example

For incremental examples that need screenshots at different stages:

from build123d import *

# Step 1: Create base box
box = Box(10, 10, 10)

# Step 2: Add fillet
filleted = fillet(box.edges(), 1)

# Step 3: Add hole
final = filleted - Cylinder(2, 10)

def main():
    from tcv_screenshots import save_model, get_saved_models

    config = {"cadWidth": 500, "height": 375}

    save_model(box, "step1_box", config)
    save_model(filleted, "step2_fillet", config)
    save_model(final, "step3_hole", {**config, "render_edges": False})

    return get_saved_models()

This generates step1_box.png, step2_fillet.png, and step3_hole.png.

Available Config Options

See VS Code CAD Viewer's show command

Examples

Display options:

  • cadWidth - Viewport width (default: 1200)
  • height - Viewport height (default: 800)
  • treeWidth - Tree panel width (default: 0)
  • theme - 'light' or 'dark' (default: 'light')
  • glass - Glass mode (default: True)
  • tools - Show tools (default: False)

Render options:

  • ambientIntensity - Ambient light intensity (default: 1.0)
  • directIntensity - Direct light intensity (default: 1.1)
  • metalness - Material metalness (default: 0.3)
  • roughness - Material roughness (default: 0.65)
  • edgeColor - Edge color as hex int (default: 0x707070)
  • render_edges - Show edges (default: True)
  • render_faces - Show faces (default: True)

Viewer options:

  • ortho - Orthographic projection (default: True)
  • control - Control type (default: 'trackball')
  • up - Up axis: 'Z' or 'Y' (default: 'Z')
  • tab - Active tab: 'tree', 'clip', 'material'
  • reset_camera - Camera view: 'iso', 'front', 'rear', 'left', 'right', 'top', 'bottom'

CI/CD

tcv_screenshots can be used in CI/CD workflows, an example can seen in .github/workflows/screenshots.yml

Development

Build the wheel:

pip install build
python -m build

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tcv_screenshots-0.3.0.tar.gz (498.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tcv_screenshots-0.3.0-py3-none-any.whl (501.6 kB view details)

Uploaded Python 3

File details

Details for the file tcv_screenshots-0.3.0.tar.gz.

File metadata

  • Download URL: tcv_screenshots-0.3.0.tar.gz
  • Upload date:
  • Size: 498.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for tcv_screenshots-0.3.0.tar.gz
Algorithm Hash digest
SHA256 40ae23c029dd2eb38eb2916e689300c4512746e0195f726b91807951148a8243
MD5 fe5e924fb2e40897d4341aa19f1f9be7
BLAKE2b-256 6fd5348850ec5363b1e1cfc3f1cf2b637ebc09800b9b4280fe49bd17be5bd1fe

See more details on using hashes here.

File details

Details for the file tcv_screenshots-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for tcv_screenshots-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 041ca50af1fc837e2628565dcea0ef78074d37a46439fdf4e56705eb5626fc5a
MD5 c1533ec4900b6aedaf4becc7d8810b1b
BLAKE2b-256 9aa0935429c12bf162b98bd0645e3a158d41763ab61caa284cf49242f105d6a9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page