Skip to content

Commit 9224a52

Browse files
committed
Support for using CadQueryNode inside cq-editor
1 parent b5d44b4 commit 9224a52

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

solid_node/node/adapters/cadquery.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
11
import os
2+
import sys
23
import time
4+
import inspect
35
import cadquery as cq
46
from solid2 import import_stl
57
from solid_node.node.leaf import LeafNode
68

79

8-
class CadQueryNode(LeafNode):
10+
def running_inside_cq_editor() -> bool:
11+
"""Detect if we are running inside CQ-Editor"""
12+
for frame in inspect.stack():
13+
module = inspect.getmodule(frame.frame)
14+
if module and module.__name__ == 'cq_editor.__main__':
15+
return True
16+
return False
17+
18+
19+
class TypeDecider(type):
20+
"""This metaclass will check if we are in the context of
21+
CQ-editor, if so, use no base classes, otherwise inherit
22+
LeafNode."""
23+
def __new__(mcs, name, bases, namespace):
24+
if running_inside_cq_editor():
25+
bases = tuple()
26+
else:
27+
bases = (LeafNode,)
28+
return super().__new__(mcs, name, bases, namespace)
29+
30+
31+
class CadQueryNode(metaclass=TypeDecider):
932
"""
1033
Represents a 3D object created using the CadQuery tool.
1134
"""

0 commit comments

Comments
 (0)