[OpenSCAD] Draft of the look and feel of a simple pythonic API for CSG

Bryan Bishop kanzure at gmail.com
Sun Feb 21 20:28:06 CET 2010


Hey Thomas,

A while ago, you and Jelle were talking about creating an API for
pythonOCC that would simplify and hide the ugly guts of OCC. I haven't
seen too much on this front in a while, but a few days ago I was
talking with Christian Siefkes, Ben Lipkowitz, and a few others about
a potential look and feel for python that would hide away OCC, or even
BRLCAD or anything else that we opt to throw under the hood.

I was wondering if I could get some thoughts on how this feels:

http://designfiles.org/~bryan/csg.py

sphere = Sphere(position=(0, 0, 0), radius="5 mm")
base = Circle(diameter="20 mm", position=(0,0,0))
cylinder = base.extrude(length="10 mm", direction=Vector(0, 0, 1))
sphere.position = (0, 0, 10)
lamp_post = cylinder.fuse(sphere)

#if you're in an X11 opengl session thingy:
display.add(lamp_post)

#or if you want to export it:
iges_data = lamp_post.to_iges()
file_handler = open("lamp_post.iges", "w")
file_handler.write(iges_data)
file_handler.close()

And maybe some parametric PAF stuff?

base = Circle("base of base plate", diameter="20 mm")
base_plate = Extrusion(base, "10mm", Vector(0,0,1))
#OR: base_plate = base.extrude("10 mm", Vector(0, 0, 1))
#OR: base_plate = extrude(base, "10 mm", Vector(0, 0, 1))
base_plate.name = "cylinder 1"

assert base_plate == Cylinder("cylinder 1", diameter="20 mm",
height="10 mm"), "Cylinder and base plate should be exactly the same"

base_plate.diameter = "25 mm"
assert base.diameter == "25 mm", "base diameter should have been updated"

base.diameter = "32 mm"
assert base_plate.diameter == "32 mm", "base plate diameter should
have been updated"

I am not entirely sure how to do this sort of feature tree. Any hints
or advice from interested bystanders would be hawt. Also, I am sending
this over to OpenSCAD because they have a similar thing going on, with
their own parser, but nevertheless would probably be interested in
python hooks and somehow influencing how those hooks feel & work.

Thanks,

- Bryan
http://heybryan.org/
1 512 203 0507


More information about the Openscad mailing list