Adding new methods to PyOpenSCAD object

3 views
Skip to first unread message

Matthieu Hendriks

unread,
Feb 21, 2026, 10:32:41 AM (4 days ago) Feb 21
to PythonSCAD
Okey, it has been quiet here for some time :)

Is there a way to add new (own) methods to the PyOpenSCAD object/model.

In python it would  normally be something like, (the example is not meant as a real method, just as an example to get the idea) : 


from openscad import *
def tx(self,x):
    self.transportX=x
    return self.translate([x,0,0])

PyOpenSCAD.tx=tx

But that gives an :

ERROR: Traceback (most recent call last):

File "<string>", line 465, in <module>

NameError: name 'PyOpenSCAD' is not defined


Execution aborted.


2e try:

from openscad import *
PyOpenSCAD = type(cube(1))
def tx(self,x):
    self.verplaatsing=x
    return self.translate(x)

PyOpenSCAD.tx=tx


Gives:

ERROR: Traceback (most recent call last):

File "<string>", line 465, in <module>

TypeError: cannot set 'tx' attribute of immutable type 'openscad.PyOpenSCAD'


Sure you can can create a wrapper around the PyOpenSCAD object but thats gives extra code which doesn't help in the clarity of the code.


Something to think about?


Reply all
Reply to author
Forward
0 new messages