Skip to content

OCP Viewer adjustments

General OCP Viewer Setup

You can influence how the OCP Viewer works. There are some settings which I find very helpfull.

This is the setup I use as a template for starting a build123d project.

1
2
3
4
5
6
from build123d import *
from ocp_vscode import *
set_defaults(reset_camera=Camera.KEEP, ortho=True, black_edges=True,measure_tools=True)
colors = ["red","blue","pink","green","orange","indigo","yellow","grey","white"]

show_all(colors=colors)

Explanation

Line 1:
This imports the code needed for build123

Line 2:
This imports the code needed for OCP Viewer

Line 3:
Camera.Keep: This will keep the perspective of the camera even after you changed your code and after letting it run again.
ortho=True:
black_edges=True: This will outline the outer edges more starkly
measure_tools=True: This will add measure tools.

Line 4:
This will color each new object in the color mentionen (so first is red, second is blue etc.)

Line 5:
Write your code here

Line 6:
Shows all objects and colors them.

OCP Color Setup

You can also define your own colors. You need to define them as RGB colors for example like this:

1
2
3
4
5
6
from build123d import *
from ocp_vscode import *
set_defaults(reset_camera=Camera.KEEP, ortho=True, black_edges=True,measure_tools=True)
colors = [(0,0,255),(0,255,0),(255,0,0)]

show_all(colors=colors)

You can also use hex values like 0xFf8833

Colormap Setup

Choosing Colormaps in Matplotlib — Matplotlib 3.8.4 documentation

from matplotlib import colormaps
list(colormaps)