Skip to content

Commit 8571f8f

Browse files
committed
fix CadQuery node to work in or outside CQ-editor
1 parent 50f2901 commit 8571f8f

1 file changed

Lines changed: 4 additions & 16 deletions

File tree

solid_node/node/adapters/cadquery.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,21 @@
66
from solid2 import import_stl
77
from solid_node.node.leaf import LeafNode
88

9-
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):
9+
class CheckCQEditor(type):
2010
"""This metaclass will check if we are in the context of
2111
CQ-editor, if so, use no base classes, otherwise inherit
2212
LeafNode."""
2313
def __new__(mcs, name, bases, namespace):
24-
if running_inside_cq_editor():
14+
if sys.modules.get('cq_editor.__main__', None):
2515
bases = tuple()
26-
else:
27-
bases = (LeafNode,)
16+
2817
return super().__new__(mcs, name, bases, namespace)
2918

3019

31-
class CadQueryNode(metaclass=TypeDecider):
20+
class CadQueryNode(LeafNode, metaclass=CheckCQEditor):
3221
"""
3322
Represents a 3D object created using the CadQuery tool.
3423
"""
35-
3624
namespace = 'cadquery.cq'
3725

3826
def as_scad(self, rendered):

0 commit comments

Comments
 (0)