File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import os
2+ import sys
23import time
4+ import inspect
35import cadquery as cq
46from solid2 import import_stl
57from 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 """
You can’t perform that action at this time.
0 commit comments