SolidCode / SolidPython

A python frontend for solid modelling that compiles to OpenSCAD
1.1k stars 172 forks source link

How do I read graphic data in a python recognized type? #137

Closed Frank-bool closed 4 years ago

Frank-bool commented 4 years ago
c = difference()(
    cylinder(r=10, h=5),
    cylinder(r=2, h=30)
)

For example, how do I read data from c in a format that python recognizes,such as math, np.array and so on.

Or how do I know if A is empty? The A here is the graph after the combination of graphics logic. Since I need to perform logical operation on the created graph, I want to know whether the graph is intersected by logical operation.

I couldn't find an operation to convert the data from solidpython into a type recognized by python.

Thank you very much!

etjones commented 4 years ago

Those would be really useful things to know, wouldn't they? Unfortunately, SolidPython is really just a translation layer from Python into OpenSCAD. All the actual geometric knowledge (like what volumes are or aren't contained in the tube you described above) is only figured out by OpenSCAD's geometry kernel. The big limitation of OpenSCAD, and by extension SolidPython, is that this information isn't really introspectable at all-- it's fine for creating an STL for 3D printing, say, but if you want to say "put thing X 30mm to the right of thing Y", you have to figure out where that would be on your own.

Depending on what you want to do, you might look in a couple other directions. Christopher Olah's ImplicitCAD is based on implicit functions, and depending on how strong your math is, might give you some more introspectable functionality. It's Haskell under the hood, though, so there's probably some language munging you'd have to do.

If you just want to visualize some things in a Python environment, there's Viewscad that will show OpenSCAD objects in Jupyter notebooks, but it sounds like you want some more power than that.

I think what you're looking for is pretty important, and I'm not sure how I'd best go about it. I think you probably want an implicit-function based approach, but I don't know of any libraries offhand that do what you want. I'll leave this open for a bit-- if you find something that works for you, please share it here!