Directives

.. cadquery-vtk:: [path_name]
Aliases
cadquery:

Provides compatibility with the CadQuery core directive.

Render a CadQuery model using kitware/vtk.js.

The path_name argument is a path to a CadQuery source file, relative to the Sphinx content root.

Examples

Default is to render the “result” object.
.. cadquery-vtk::

    result = cadquery.Workplane().box(2, 2, 0.5)
Set the height of the VTK.js render window.
.. cadquery-vtk::
    :height: 100px

    result = cadquery.Workplane().box(2, 2, 0.5)
Load CadQuery source code from a file.
.. cadquery-vtk:: ../examples/simple-rectangular-plate.py

VTK JavaScript is generated using the CadQuery Gateway Interface and cadquery.occ_impl.assembly.toJSON().

New in version 0.2.0: Identical to depreciated cadquery directive.

Options

:align: (left|center|right (optional, default = none))

Horizontal alignment of render.

:color: (list of RGBA values (optional, default = 1, 0.8, 0, 1))

Default color of render in RGBA notation. Defined as a space- or comma-separated list of channel values between 0 and 1.

:height: (length or unitless (optional, default = 500px))

Define the height of VTK.js render window. Value is used for the CSS height property.

:select: (name of shape to render (optional, default = result))

Select the CadQuery object to render.

:width: (length or percentage or unitless (optional, default = 100%))

Define the width of the VTK.js render window. Value is used for the CSS width property.

.. cadquery-svg::
Aliases
cq_plot:

Provides compatibility with the CadQuery core directive.

Render a CadQuery model using SVG.

Tip

The CadQuery source must call show_object().

Examples

Render the object passed to “show_object()” as a SVG image.
.. cadquery-svg::

    result = cadquery.Workplane().box(2, 2, 0.5)
    show_object(result)

The SVG image is generated using the CadQuery Gateway Interface and the CadQuery SVG exporter .

New in version 0.2.0: Identical to depreciated cq_plot directive.

.. cadquery:vtk::

Render a CadQuery model using kitware/vtk.js. Differs from cadquery-vtk in that it is rendered as a figure node.

Development Status

Development Status:

2 - Pre-Alpha

This directive is experimental.

A cadquery:vtk directive consists of:

  1. A paragraph to be used as the caption (or empty comment to omit a caption), and;

  2. a code-block or literalinclude from which the source is extracted to render the model, and;

  3. optional additional content that follows will be used as notes.

There must be a blank line before each of the caption, paragraph, and code block. If notes are included then they must separated from the code block by a blank line. To specify an empty caption, use an empty comment (“..”) in place of the caption.

Refer to the cadquery:vtk examples section for demonstrations of the various options.

VTK JavaScript is generated using the CadQuery Gateway Interface and cadquery.occ_impl.assembly.toJSON().

New in version 0.8.0.

Examples

Code block: with caption, source, and notes
.. cadquery:vtk::

    A simple rectangular plate measuring 2 × 2 × 0.5 mm.

    .. code-block:: python
        :name: cq-rectangular-plate
        :linenos:
        :emphasize-lines: 5

        """Simple rectangular plate."""

        import cadquery as cq

        result = cadquery.Workplane().box(2, 2, 0.5)

    .. rubric:: Notes:

    #. Line numbers are added with ``linenos``.
    #. Line number 5 is emphasized with ``emphasize-lines``.
Code block: without caption or source
.. cadquery:vtk::
    :include-source: no

    ..

    .. code-block:: python

        """Simple rectangular plate."""

        import cadquery as cq

        result = cadquery.Workplane().box(2, 2, 0.5)
Source from file: with caption, source, and notes
.. cadquery:vtk::

    A simple rectangular plate measuring 2 × 2 × 0.5 mm.

    .. literalinclude:: ../../examples/simple-rectangular-plate.py

    Notes may follow the ``literalinclude``.

    :Material: stainless steel
    :Finish: brushed

Options

:name: (a label for hyperlink (optional))

Define an implicit target name that can be referenced using :ref:`label-name`.

:align: (left|center|right (optional, default = none))

Horizontal alignment of figure element.

:color: (list of RGBA values (optional, default = 1, 0.8, 0, 1))

Default color of render in RGBA notation. Defined as a space- or comma-separated list of channel values between 0 and 1.

:figclass: (space separated list of class names (optional))

Add classes to the figure element.

:figwidth: (length or percentage or unitless (optional, default = 100%))

Define the width of the figure element. Value is used for the CSS width property.

:height: (length or unitless (optional, default = 500px))

Define the height of VTK.js render window. Value is used for the CSS height property.

:select: (name of shape to render (optional, default = result))

Select the CadQuery object to render.

:include-source: (yes|no (optional))

Whether to include CadQuery source code listing. Defaults to cadquery_include_source.

.. cadquery:svg::

Render a CadQuery model using SVG.

Development Status

Development Status:

2 - Pre-Alpha

This directive is experimental.

A cadquery:svg directive consists of:

  1. A paragraph to be used as the caption (or empty comment to omit a caption), and;

  2. a code-block or literalinclude from which the source is extracted to render the model, and;

  3. optional additional content that follows will be used as notes.

There must be a blank line before each of the caption, paragraph, and code block. If notes are included then they must separated from the code block by a blank line. To specify an empty caption, use an empty comment (“..”) in place of the caption.

Refer to the cadquery:svg examples section for demonstrations of the various options.

The SVG image is generated using the CadQuery SVG exporter.

New in version 0.8.0.

Examples

Code block: with caption, source, and notes
.. cadquery:svg::
    :alt: A rectangular plate

    A simple rectangular plate measuring 2 × 2 × 0.5 mm.

    .. code-block:: python
        :name: cq-rectangular-plate
        :linenos:
        :emphasize-lines: 5

        """Simple rectangular plate."""

        import cadquery as cq

        result = cadquery.Workplane().box(2, 2, 0.5)

    .. rubric:: Notes:

    #. Line numbers are added with ``linenos``.
    #. Line number 5 is emphasized with ``emphasize-lines``.
Code block: without caption or source
.. cadquery:svg::
    :include-source: no

    ..

    .. code-block:: python

        """Simple rectangular plate."""

        import cadquery as cq

        result = cadquery.Workplane().box(2, 2, 0.5)
Source from file: with caption, source, and notes
.. cadquery:svg::

    A simple rectangular plate measuring 2 × 2 × 0.5 mm.

    .. literalinclude:: ../../examples/simple-rectangular-plate.py

    Notes may follow the ``literalinclude``.

    :Material: stainless steel
    :Finish: brushed

Options

:name: (a label for hyperlink (optional))

Define an implicit target name that can be referenced using :ref:`label-name`.

:align: (left|center|right (optional, default = none))

Horizontal alignment of figure element.

:alt: (text (optional, default = "SVG image exported by CadQuery.")))

Alternative text used for for the alt attribute on the <img> element.

:figclass: (space separated list of class names (optional))

Add classes to the figure element.

:figwidth: (length or percentage or unitless (optional, default = 100%))

Define the width of the figure element. Value is used for the CSS width property.

:inline-uri: (flag)

Include the SVG image in-line using the data URI scheme:

<img src="data:image/svg+xml;base64,PD94bWwgdm…">

Default is to reference the image with a relative URL:

<img src="../_static/cadquery-exports/995c440e.svg">
:select: (name of shape to render (optional, default = result))

Select the CadQuery object to render.

:include-source: (yes|no (optional))

Whether to include CadQuery source code listing. Defaults to cadquery_include_source.