Welcome! Log In Create A New Profile

Advanced

Pass Module name in variable to other (generic) module ?

Posted by Replace 
Pass Module name in variable to other (generic) module ?
January 15, 2017 02:14PM
Can I call a module () with the name of another module as a parameter ?

for instance, to cut-off everything below z=0, I difference the object with a cube that is below z=0.
If I make a generic cut-off module, I could call that one, supply the name of the object module and it will cut the remainder off.

i have more idea's to process other modules ... for instance, punch a hole in them, this way.

Can this be done ?

Thomas


www.3daybreaker.blogspot.com

Orca V4.4 rebuild to Ramps with Mk8 and E3D, as well as a Rostock Delta Mini and an OLO in backorder :-)
Re: Pass Module name in variable to other (generic) module ?
January 16, 2017 12:37AM
I doubt that there is any way in OpenScad to pass the name of a module to be called as a parameter.

However, OpenScad has probably an even better alternative: the concept of children!

So you can easily create a module such as e.g.:
module cutbelow(z=0,max=100){
   difference(){
     children();
     translate([-max,-max,z-max])cube([2*max,2*max,max]);
   }
}

which will take whatever follows and cut away everything below z=0 (or whatever z value is specified), such as
cutbelow()sphere(r=20);

or

cutbelow(z=-5)rotate([45,0,0])cylinder(r=20,h=40);


Re: Pass Module name in variable to other (generic) module ?
January 17, 2017 09:24AM
Ahh,
nice solution. Definitely gonna do that stuff.

So 'Children' is in fact the united instructions you perform a function on ?
Or do I miss it ?


www.3daybreaker.blogspot.com

Orca V4.4 rebuild to Ramps with Mk8 and E3D, as well as a Rostock Delta Mini and an OLO in backorder :-)
Re: Pass Module name in variable to other (generic) module ?
January 17, 2017 10:19AM
OpenScad's children() will execute all or some of the constructs which follow the module call. For more than one "child", the "children" are surrounded by brackets. So, looked at from this point of view, the standard difference() is actually subtracting children([1:$children-1]) from children(0).
Sorry, only registered users may post in this forum.

Click here to login