bernhard-42 / vscode-ocp-cad-viewer

A viewer for OCP based Code-CAD (CadQuery, build123d) integrated into VS Code
Apache License 2.0
96 stars 10 forks source link

OCP CAD Viewer for VS Code

OCP CAD Viewer for VS Code is an extension to show CadQuery and build123d objects in VS Code via the three-cad-viewer viewer component.

Installation

Prerequisites

Notes:

Installation

  1. Open the VS Code Marketplace, and search and install OCP CAD Viewer 2.4.1.

    Afterwards the OCP viewer is available in the VS Code sidebar:

  2. Clicking on it shows the OCP CAD Viewer UI with the viewer manager and the library manager:

    You have 3 options:

    • Prepare OCP CAD Viewer for working with build123d: Presse the Quickstart build123d button.

      This will install OCP, build123d, ipykernel (_jupyterclient), _ocptessellate and _ocpvscode via pip (except for Apple Silicon machines that require mamba and will also install cadquery)

    • Prepare OCP CAD Viewer for working with CadQuery: Presse the Quickstart CadQuery button.

      This will install OCP, CadQuery, ipykernel (_jupyterclient), _ocptessellate and _ocpvscode via pip (except for Apple Silicon machines that require mamba)

    • Ignore the quick starts and use the "Library Manager" to install the libraries. Doing so, OCP CAD Viewer let's you select whether to use pip, mamba, conda or poetry. Install the needed library by pressing the down-arrow behind the library name (hover over the library name to see the button) in the "Library Manager" section of the OCP CAD Viewer sidebar. For more details, see here

    The Quickstarts will also

  3. On Silicon Macs (ARM CPU)

    • Install Miniforge
      • Option 1: Download and install from the Miniforge github page
      • Option 2: Use homebrew: brew install miniforge
    • Initialize your shell for mamba: mamba init $(basename "$SHELL")
    • Create an environment, e.g named code_cad with Python 3.10: mamba create -n code_cad python=3.10
    • Activate the environment: mamba activate code_cad
    • Start VS Code from your working folder: code .
    • Install the Python extension in VS Code
    • Continue with 1. above

Note: Do not use the OCP CAD Viewer logo to verify your OCP CAD Viewer settings! The logo overwrites all your settings in VS Code with its own settings to always look the same on each instance. Use a simple own model for checking your conmfiguration

Usage

Running code using Jupyter

Running code

Debugging code with visual debugging

After each step, the debugger checks all variables in locals() for being CAD objects and displays them with their variable name. Note:

Debugging code

Library Manager

You can also use "Library Manager" in the OCP CAD Viewer sidebar to manage the Python libraries for build123d, cadquery, ipython and _ocptessellate (Presse the down-arrow when hovering over a library name to install/upgrade it)

Extra topics

Best practices

Development

Testing:

Native tessellator can be set via NATIVE_TESSELLATOR=1and Python tessellator via NATIVE_TESSELLATOR=0.

When OCP_VSCODE_PYTEST=1 is set, show will not send the tessellated results to the viewer, but return it to the caller for inspection.

A full test cycle consist of:

NATIVE_TESSELLATOR=0 OCP_VSCODE_PYTEST=1 pytest -v -s pytests/
NATIVE_TESSELLATOR=1 OCP_VSCODE_PYTEST=1 pytest -v -s pytests/

Troubleshooting

Changes

v2.4.1

v2.4.0

New features

Fixes

full change log see CHANGELOG.md