Skip to content

Commit

Permalink
added openscad.assemble
Browse files Browse the repository at this point in the history
  • Loading branch information
Henning Meyer committed Jun 3, 2011
1 parent 5bddc9a commit a16ff40
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.textile
Expand Up @@ -70,8 +70,8 @@ As OpenSCADpy is forked from OpenSCAD, you might want to look at the "OpenSCAD H
h3. Reference

All objects are defined in Python language. All OpenSCAD specific methods are part of the openscad-module - so most likely you want to import this module to the global namespace: @from openscad import *@
When all your code is executed OpenSCADpy will render the content of the variable @openscad.result@
@openscad.result = openscad.sphere(10)@ would create a sphere (with r=10).
OpenSCADpy will render the content of the call @openscad.assemble()@
@openscad.assemble( openscad.sphere(10) )@ would create a sphere (with r=10).

The following is a list of all object classes in OpenSCADpy.

Expand Down
2 changes: 1 addition & 1 deletion examples/example001.py
Expand Up @@ -15,4 +15,4 @@ def r_from_dia(d):
- rotcy([1,0,0], cy_r, cy_h)
- rotcy([0,1,0], cy_r, cy_h))

openscad.result = example001()
openscad.assemble( example001() )
2 changes: 1 addition & 1 deletion examples/example002.py
Expand Up @@ -11,5 +11,5 @@ def example002():
) & translate([0, 0, 5],
cylinder(h=50, r1=20, r2=5, center=True))

openscad.result = example002();
assemble( example002() )

2 changes: 1 addition & 1 deletion examples/example003.py
Expand Up @@ -13,5 +13,5 @@ def example003():
)


openscad.result = example003()
assemble( example003() )

2 changes: 1 addition & 1 deletion examples/example004.py
Expand Up @@ -3,5 +3,5 @@
def example004():
return cube(30, True) - sphere(20)

openscad.result = example004()
assemble( example004() )

2 changes: 1 addition & 1 deletion examples/example005.py
Expand Up @@ -18,4 +18,4 @@ def example005():
)


openscad.result = example005()
assemble( example005() )
5 changes: 2 additions & 3 deletions examples/example006.py
Expand Up @@ -22,7 +22,7 @@ def edgeprofile():
[+1, -1, 270]])
)
,[ [0, 0, 0], [1, 0, 0], [0, 1, 0] ])
+ map(lambda i: rotate(i[0],[0,0,1],
+ map(lambda i: rotate(i[0],[0,0,1], child=
rotate(ang=i[1],vec=[1,0,0], child=
translate([0,-50,0],
map(lambda j: translate([j[0],0,j[1]],
Expand All @@ -41,5 +41,4 @@ def edgeprofile():
])
)

openscad.result = example006()
print openscad.result
assemble( example006() )
4 changes: 2 additions & 2 deletions examples/example007.py
Expand Up @@ -43,8 +43,8 @@ def cutview():
difference(combo),r
])

openscad.result = translate([0, 0, -10],
clip())
assemble( translate([0, 0, -10],
clip()) )

#openscad.result = cutview()

11 changes: 10 additions & 1 deletion src/pythonscripting.cc
Expand Up @@ -51,7 +51,7 @@ using namespace boost::python;
using boost::make_shared;

list empty_list;

class PyAbstractNode;

class PyContext {
Accuracy acc;
Expand All @@ -78,6 +78,9 @@ class PyContext {
return openscad_namespace[nsresult];
return object();
}
void setResult(const PyAbstractNode &n) {
openscad_namespace[nsresult] = n;
}
Accuracy &getAcc() {
acc.fn = extract<double>(openscad_namespace["fn"]);
acc.fa = extract<double>(openscad_namespace["fa"]);
Expand Down Expand Up @@ -609,6 +612,11 @@ list pyDxfCross(const std::string &filename, const std::string &layername=std::s

BOOST_PYTHON_FUNCTION_OVERLOADS(pyDxfCross_overloads, pyDxfCross, 1, 4)

void assemble(const PyAbstractNode &n) {
ctx.setResult(n);
}


BOOST_PYTHON_MODULE(openscad) {
namespace py = boost::parameter::python;
namespace mpl = boost::mpl;
Expand Down Expand Up @@ -705,6 +713,7 @@ BOOST_PYTHON_MODULE(openscad) {
*/
def("DxfDim", pyDxfDim, pyDxfDim_overloads());
def("DxfCross", pyDxfCross, pyDxfCross_overloads());
def("assemble", assemble);
}

PythonScript::PythonScript(double time) {
Expand Down

0 comments on commit a16ff40

Please sign in to comment.