exec fails with simple (an natural) approaches:
import cadquery as cq
l = 1
w = 2
h = 3
def box():
return cq.Workplane().box(l, w, h).edges().fillet(0.1)
show(box())
fails with
File "<string>", line 9, in box
NameError: name 'cq' is not defined
So let's change it (just for the test, I would never program like that):
l = 1
w = 2
h = 3
def box():
import cadquery as cq
return cq.Workplane().box(l, w, h).edges().fillet(0.1)
show(box())
Now, this fails with
File "<string>", line 9, in box
NameError: name 'l' is not defined
exec just doesn't play well with global variables
Of course, this works:
def box(l=1, w=2, h=3):
import cadquery as cq
return cq.Workplane().box(l, w, h).edges().fillet(0.1)
show(box())
However I would need to adapt my style of coding - especially for quick hacks - to the limitations of exec.
Maybe there is a more robust way?