r/OpenPythonSCAD • u/TurboProgrammer0815 • Dec 19 '25
How to use functions from OpenSCAD files?
Simple and short question:
How do I do this?
// func.scad
function foo() = 10;
# test.py
func = osuse("func.scad")
cube(func.foo())Looks straight forward, but I'm getting this error:
AttributeError: 'openscad.PyOpenSCAD' object has no attribute 'foo'
Does anyone have an idea?Simple and short question:How do I do this?// func.scad
function foo() = 10;
# test.py
func = osuse("func.scad")
cube(func.foo())Looks straight forward, but I'm getting this error:AttributeError: 'openscad.PyOpenSCAD' object has no attribute 'foo'Does anyone have an idea?
3
Upvotes
View all comments
Show parent comment
2
u/TurboProgrammer0815 Dec 19 '25
First of all I don't think it's possible to refactor functions into modules. Functions return different kinds of variables, whereas modules only return 2D or 3D objects.
And secondly, I want to be able to use existing OpenSCAD libraries, for example this one:
https://github.com/kennetek/gridfinity-rebuilt-openscad
So even if it were possible to refactor functions into modules, I would not want to patch 3rd-party libraries.
So I had a look at the source and found out, that this feature is not implemented.
Or better: It was not implemented yet ;-).
https://github.com/pythonscad/pythonscad/pull/233
Once this is merged, functions from imported OpenSCAD files could just be called from within Python, the same way as it is possible to call modules.