-
Notifications
You must be signed in to change notification settings - Fork 26
Extra syntactic sugar
SolidPython overrides the basic operators + and | (union), - (difference), * and & (intersection) and ~ (debug). So
c = cylinder(r=10, h=5) + cylinder(r=2, h=30)
is the same as:
c = union()(
cylinder(r=10, h=5),
cylinder(r=2, h=30)
)
Likewise:
c = cylinder(r=10, h=5)
c -= cylinder(r=2, h=30)
is the same as:
c = difference()(
cylinder(r=10, h=5),
cylinder(r=2, h=30)
)
Since at least some people (including me) don't like the OpenSCAD Syntax, SolidPython 2.x.x introduces the support for the so called "Access-Style-Syntax". This enables you to call some of the SolidPython / OpenSCAD functions as member functions of any OpenSCADObject instead of wrapping it in an instance of it.
In other words, e.g. code:
up(10)(cube(1))
#is equal to
cube(1).up(10)
The available member functions are the following:
union, difference, intersection, translate, scale, rotate, mirror, resize,
color, offset, hull, render, projection, surface, linear_extrude,
rotate_extrude, debug, background, root and disable
Also the convenience functions are available:
up, down, left, right, forward, fwd, back, translateX, translateY, translateZ,
rotateX, rotateY, rotateZ, mirrorX, mirrorY, mirrorZ, scaleX, scaleY, scaleZ,
resizeX, resizeY, resizeZ
Furthermore you can chain these functions, because they all return the transformed OpenSCADObject, e.g.:
cube(1).up(10).back(20).rotate(10, 0, 5).mirror(1, 0, 0).color("green").root()
SolidPython includes a number of convenience functions. Currently these include:
Directions for arranging things:
up, down, left, right, forward, fwd, back
Transformations per dimension:
translateX, translateY, translateZ, rotateX, rotateY, rotateZ, mirrorX,
mirrorY, mirrorZ, resizeX, resizeY, resizeZ, scaleX, scaleY, scaleZ
Furthermore the operations translate, scale, resize, mirror, rotate, cube and square are overwritten in a way that they accept single integer or float values as first parameter. (translate(1, 2, 3) equals translate([1, 2, 3]))
cylinder().rotateY(90).up(10)
seems a lot clearer to me than:
translate([0,0,10])(
rotate([0, 90, 0])(
cylinder()
))