[OpenSCAD] modifying default-parameters / accessing children of children?

Roland Koebler rk-list at simple-is-better.org
Mon Jun 6 12:55:20 EDT 2016


Hi,

I'm heavily using modules with default-parameters. Now, I would like to
locally use different default-parameters, so I don't need to give the
"new default parameters" at each module-invokation.

One way that looked sensible to me, is using a wrapper-module with
different default-parameters, but that doesn't work when using
children(i) in the module.

Questions:

- Is there a way to locally modify default-parameters?
- Is there a way to access the children of children or to unpack a group?


Details:

1. Example of a working wrapper-module:

   - Original module:

	module foo(a=1, b=2, c=3, d=4)
	{
	    ...
	}

    - Wrapper-module, to locally use different default-parameters, e.g. a=5, b=6.

	module myfoo(a=5, b=6, c=3, d=4)
	{
	    foo(a,b,c,d);
	}

    This works well, as long as "foo" doesn't use children(i).

2. Example with children:

   - Original module + invocation
     (slightly modified example from the documentation):

	module lineup(space=10)
	{
	    for(i=[0:$children-1])
		translate([space*i,0,0]) children(i);
	}

	lineup() {
	    sphere(d=8);
	    cube(7, center=true);
	    cylinder(d=7.5, h=8, center=true);
	}

    - Wrapper-module + invocation:
    
	module mylineup(space=20)
	{
	    lineup(space)
	    children();
	}

	mylineup() {
	    sphere(d=8);
	    cube(7, center=true);
	    cylinder(d=7.5, h=8, center=true);
	}

    Now, this fails, since lineup() now only sees 1 child, which
    consists of sphere+cube+cylinder.

    The following would work, but only for a defined number of children:

	module mylineup(space=20)
	{
	    lineup(space) {
		children(0);
		children(1);
		children(2);
	    }
	}

    So, is it possible to (a) unpack children, (b) access the children
    of children or (c) use some other way/workaround?


Best regards
Roland




More information about the Discuss mailing list