occmodel as Python alternative to openscad

I like openscad a lot, but I'm still on the lookout for alternatives.

Recently I ran across occmodel. Its biggest prerequisite, OpenCASCADE, is packaged in Debian Stretch as "liboce"; the rest are fairly lightweight (though compiled) extensions.

So I gave it a try for a small piece, little extension legs for a dish drainer. I plan to add two leg extensions to the antisinkward legs of the dish drainer, to improve its draining behavior. So one key feature is that the captured leg will end up being at an angle to the counter.

My python program has a few "configurables" near the top, inner and outer diameters, heights, and the distance between the legs. From this, I do some basic operations (difference of two cylinders, rotation of that intermediate solid to represent the required angle, then intersection between it and a large cube that represents the half-space 'above the countertop'. Then, just to show I can do something openscad can't do trivially, I fillet every edge by 1mm.

from __future__ import division
from math import *
from geotools import *
from tostl import occ_to_stl # a little homebrew module
import os

IN=25.4

dist = 12*IN
dia = .7*IN
od = dia + .25*IN
elevation = 1*IN
engagement = 1*IN

angle = atan2(elevation, dist)

outer = Solid().createCylinder((0,0,-elevation), (0,0,elevation+engagement),od/2)
inner = Solid().createCylinder((0,0,elevation), (0,0,100),dia/2)
outer.cut(inner)
outer.rotate(angle, (1,0,0))
b = Solid().createBox((-100,-100,0), (100,100, 100))
outer.common(b)
outer.fillet(1)
with open("drainboots.stl.new", "wb") as f: occ_to_stl(outer, f)
os.rename("drainboots.stl.new", "drainboots.stl")

(I couldn't get a screenshot that did the part much justice)

What is the gap between here and a real OpenSCAD alternative?

First, I'm not confident of the robustness of liboce; I saw some segfaults and since they were dependent on specific numbers in the geometry I am tempted to assign blame there and not to the occmodel wrapper. (not that OpenSCAD is beyond reproach here)

Second, it needs an integrated environment like OpenSCAD has. Maybe one of the python "notebook" interfaces would be suitable for this.

Third, it needs less boilerplate.

Fourth, it needs broad buy-in by users of sites like thingiverse, because OpenSCAD has massive momentum behind it.

Entry first conceived on 1 August 2017, 0:48 UTC, last modified on 4 August 2017, 23:52 UTC
Website Copyright © 2004-2024 Jeff Epler