Skip to content

Instantly share code, notes, and snippets.

@proegssilb
Created June 1, 2024 12:48
Show Gist options
  • Save proegssilb/153b5a9d4c2137de714ec5c8542c0d9d to your computer and use it in GitHub Desktop.
Save proegssilb/153b5a9d4c2137de714ec5c8542c0d9d to your computer and use it in GitHub Desktop.
Build123d template for avoiding show_all and switching between VSCode and CQEditor
# OCP Setup
ocp_enable = True
try:
from ocp_vscode import show, show_all, reset_show, set_port, set_colormap, ColorMap, Camera, show_object
except ImportError:
ocp_enable = False
else:
set_port(3939)
reset_show()
# Model code goes here
classes = (BuildPart, BuildSketch, BuildLine)
# classes = (BuildPart, BuildSketch, BuildLine, Sketch, Part)
if ocp_enable:
set_colormap(ColorMap.seeded(colormap="rgb", alpha=1, seed_value="vscod"))
variables, s_o, s_n, slocal = (list(cf().f_locals.items()), [], [], False)
for name, obj in variables:
if (
isinstance(obj, classes)
and not name.startswith("_")
and not name.startswith("obj")
):
if not hasattr(obj, '_obj_name'):
s_o.append(obj), s_n.append(f"{name}")
elif obj._obj_name != "sketch" or slocal:
s_o.append(obj), s_n.append(f"{name}.{obj._obj_name}")
elif obj._obj_name == "sketch":
s_o.append(obj.sketch), s_n.append(f"{name}.{obj._obj_name}")
if ocp_enable:
show(
*s_o,
# ,
names=s_n,
reset_camera=Camera.KEEP,
measure_tools=True,
)
else:
options = {}
for (obj, name) in zip(s_o, s_n):
show_object(obj, name=name, options=options)
m = Mesher()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment