Skip to main content

cadquery-png-plugin

cadquery-png-plugin is a PNG export plugin for CadQuery, which is a Python API for creating CAD models and assemblies. The core CadQuery library can export SVG images, but not bitmap images, such as PNG.

Installation

This plugin has not been released on PyPI, but it can be installed via git and pip.

pip install git+https://github.com/jmwright/cadquery-png-plugin.git

This installation will also install other required packages such as CadQuery if the environment does not already include them.

Usage

Below is a minimal example of this plugin being used to export a CadQuery assembly.

import cadquery as cq
import cadquery_png_plugin.plugin  # This registers the plugin with CadQuery

# You can customize the render options through a dictionary
render_options = {"width": 600,  # width of the output image
                  "height": 600,  # height of the output image
                  "color_theme": "default",  # can also be black_and_white
                  "view": "front-top-right",  # front, top, front-bottom-left, etc
                  "zoom": 1.0  # zooms in and out on the center of the model
                  }

# Create a simple CadQuery assembly for an example export
box = cq.Workplane().box(10, 10, 10)
cyl = cq.Workplane().circle(2.5).extrude(5)
assy = cq.Assembly(box, color=cq.Color(1.0, 0.0, 0.0))
# assy.add(box, color=cq.Color(1.0, 0.0, 0.0))
assy.add(cyl, loc=cq.Location(0, 0, 5.0), color=cq.Color(0.0, 0.0, 1.0))

# Do the PNG export
assy.exportPNG(options=render_options, file_path="ouptput_file.png")

That code results in the following image.

Sample PNG based on the script above

It is also possible to pass a dictionary for the view parameter rather than using a named view. This allows for custom views. The view values provided below are equivalent to passing the string front-top-right for the view parameter. The parameter values shown below are also the default values for the view if any of the custom view parameters are omitted from the dictionary.

render_options = {
    "width": 1200,
    "height": 1200,
    "color_theme": "default",
    "view": {
        "view_up": (0, 1, 0),
        "azimuth": 45,
        "elevation": -45,
        "roll": -55,
        "window_center_x": -0.05,
        "window_center_y": -0.05
    },
    "zoom": 1.0,
    "background_color": (1, 1, 1),
}

Where this Plugin is Used

An example of this plugin being used by a project in the wild can be found in the Nimble repository.

Running Tests

  1. Clone the repository.
https://github.com/jmwright/cadquery-png-plugin.git && cd cadquery-png-plugin
  1. Install the plugin and its development dependencies.
pip install -e .
pip install -e .[dev]
  1. Run the tests
pytest

Metadata

Release files for cadquery-png-plugin 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cadquery-png-plugin 1.1.0
File Size Uploaded
cadquery_png_plugin-1.1.0.tar.gz 23.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cadquery-png-plugin 1.1.0
File Interpreter ABI Platform
cadquery_png_plugin-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 36.5 kB

Release files / cadquery_png_plugin-1.1.0.tar.gz

Download URL cadquery_png_plugin-1.1.0.tar.gz
Size 23.0 kB
Tags Source
SHA-256 checksum
How to use checksums
eda5e686c694dc7821d5ff917b6f3b70e4fa03bfbcf0d5d6990db628c48be9ae
BLAKE2b-256 checksum
How to use checksums
3c28009f6f5fbe8c414cdac27817690b4d716d2d0fb0952ecc444ccbbce255f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.2

Release files / cadquery_png_plugin-1.1.0-py3-none-any.whl

Download URL cadquery_png_plugin-1.1.0-py3-none-any.whl
Size 13.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d382ae8a33fa17a1fd5dc9ec455372e0994d69e229be6fbb87d605a90fbfca0b
BLAKE2b-256 checksum
How to use checksums
9466e514b742100632d7ae092d41d3fd4a562dbaab63090e18fc0c27562b0460
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.2

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page