Skip to main content

A PNG export plugin for CadQuery.

Project description

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

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

cadquery_png_plugin-1.1.0.tar.gz (23.0 kB view details)

Uploaded Source

Built Distribution

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

cadquery_png_plugin-1.1.0-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file cadquery_png_plugin-1.1.0.tar.gz.

File metadata

  • Download URL: cadquery_png_plugin-1.1.0.tar.gz
  • Upload date:
  • Size: 23.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for cadquery_png_plugin-1.1.0.tar.gz
Algorithm Hash digest
SHA256 eda5e686c694dc7821d5ff917b6f3b70e4fa03bfbcf0d5d6990db628c48be9ae
MD5 be47e986f03d795fd6c41f9856564bbb
BLAKE2b-256 3c28009f6f5fbe8c414cdac27817690b4d716d2d0fb0952ecc444ccbbce255f4

See more details on using hashes here.

File details

Details for the file cadquery_png_plugin-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cadquery_png_plugin-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d382ae8a33fa17a1fd5dc9ec455372e0994d69e229be6fbb87d605a90fbfca0b
MD5 75bfed6874066cd3edb3ca6d09a632ba
BLAKE2b-256 9466e514b742100632d7ae092d41d3fd4a562dbaab63090e18fc0c27562b0460

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