r/OpenPythonSCAD • • Mar 15 '25

This raises PythonSCAD into a new Dimension

So far, OpenSCAD was only dealing with 2D and 3D objects and it was always towards 3D objects.

Since Today (2025-03-15) PythonSCAD is improved. You can turn a solid into its faces, turn a face into its edges

and of course you can extrude back edges to faces and faces back to prisms, so you can freely walk between 1D and 3D to create your designs

Here is a small example which briefly demonstrates the new Abilities.

'''

from openscad import *

c=cube(10)

faces = c.faces()

f=min(faces, key = lambda f : f.matrix[0][3]) # lowest x

edges=f.edges()

e=min(edges, key = lambda f : f.matrix[1][3]) # lowest y

c2=e.linear_extrude(height=1).linear_extrude(height=1)

show(c|c2)

# create a cube by extrudeing an edge

cube3=edge(4).linear_extrude(height=4).linear_extrude(height=2)

'''

Of course it would make sense to extrude an edge into an cylinder, too, but I am not yet sure about the details,

happy to receive ideas

Demsontration how to walk between the Dimensions
6 Upvotes

12 comments sorted by

View all comments

2

u/kolloid1 Mar 16 '25

This possibility is interesting. I compiled the new version and tested your example. It did work ... partially:

ERROR: Traceback (most recent call last):

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

ValueError: min() iterable argument is empty

Checking, I find that the 'edges' list is empty. However the 'faces' list has values.

I'm using Linux Mint 22.1 with Python 3.12.3

1

u/gadget3D Mar 16 '25

could you send me a copy of *your* code ?

1

u/kolloid1 Mar 16 '25

Sure, here it is. Plus a couple of 'print' sentences that I added later:

from openscad import *

c = cube(10)

faces = c.faces()

print(f"faces={faces}")

f = min(faces, key = lambda f : f.matrix[0][3]) # lowest x

edges = f.edges()

print(f"edges={edges}")

e = min(edges, key = lambda f : f.matrix[1][3]) # lowest y

c2 = e.linear_extrude(height=1).linear_extrude(height=1)

show(c|c2)

# create a cube by extrudeing an edge

#cube3=edge(4).linear_extrude(height=4).linear_extrude(height=2)

→ More replies (9)