discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Re: [OpenSCAD] Passing objects as arguments?

M
MichaelAtOz
Tue, Jan 3, 2017 3:03 AM

Hi zapta,

Welcome to the forum. Your post is still flagged as "This post has NOT been
accepted by the mailing list yet", so nobody gets it unless they look.
You need to subscribe to the  mailing list
http://forum.openscad.org/mailing_list/MailingListOptions.jtp?forum=1  ,
and respond to the registration email.

Also, don't use <"raw"> Nabble forum s/w cuts it out of the mailing list,
use <"quote"> instead - DON'T use the 'quote' button, it inserts the
original message, like so

zapta wrote

Is it possible to write operator that will take an object as an argument?
For example, in the program below the module

/

my_part_with_first_layer_inset()

/

takes the output of

/

my_part()

/

and insets its first layer. I would like to write it as a general
operator that can accept

/

my_part

/

as an argument. for example

/

inset(my_part())

/

or

/

inset() my_part()

/

rather than relying on a hard coded name my_part().

This is how to do it:

eps = 0.01;
inset_width = 0.3;
inset_height = 0.2;

// An arbitrary part wich is placed at z=0.
module my_part() {
difference() {
translate([-5, -5, 0]) cube([10, 10, 5]);
cube([6, 6, 20], center=true);
}
}

// The arbitrary part with first layer inset.
module my_part_with_first_layer_inset() {
difference() {
children();  // <<==== pass this as an arg
cube([100, 100, 2*inset_height], center=true);
}
linear_extrude(height=inset_height+eps)
offset(r = -inset_width)
projection(cut=true)
children();  // <<==== pass this as an arg
}

my_part_with_first_layer_inset()
my_part();  // <<==== pass this as an arg

translate([0,20,0])
color("orange")
my_part();

translate([20,0,0])
my_part_with_first_layer_inset(inset_width=2)
cylinder(d=20,h=2);


Admin - PM me if you need anything, or if I've done something stupid...

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.

The TPP is no simple “trade agreement.”  Fight it! http://www.ourfairdeal.org/  time is running out!

View this message in context: http://forum.openscad.org/Passing-objects-as-arguments-tp19877p19879.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Hi zapta, Welcome to the forum. Your post is still flagged as "This post has NOT been accepted by the mailing list yet", so nobody gets it unless they look. You need to subscribe to the mailing list <http://forum.openscad.org/mailing_list/MailingListOptions.jtp?forum=1> , and respond to the registration email. Also, don't use <"raw"> Nabble forum s/w cuts it out of the mailing list, use <"quote"> instead - DON'T use the 'quote' button, it inserts the original message, like so zapta wrote > Is it possible to write operator that will take an object as an argument? > For example, in the program below the module / > my_part_with_first_layer_inset() / > takes the output of / > my_part() / > and insets its first layer. I would like to write it as a general > operator that can accept / > my_part / > as an argument. for example / > inset(my_part()) / > or / > inset() my_part() / > rather than relying on a hard coded name my_part(). > This is how to do it: > eps = 0.01; > inset_width = 0.3; > inset_height = 0.2; > > // An arbitrary part wich is placed at z=0. > module my_part() { > difference() { > translate([-5, -5, 0]) cube([10, 10, 5]); > cube([6, 6, 20], center=true); > } > } > > // The arbitrary part with first layer inset. > module my_part_with_first_layer_inset() { > difference() { > children(); // <<==== pass this as an arg > cube([100, 100, 2*inset_height], center=true); > } > linear_extrude(height=inset_height+eps) > offset(r = -inset_width) > projection(cut=true) > children(); // <<==== pass this as an arg > } > > my_part_with_first_layer_inset() > my_part(); // <<==== pass this as an arg > > translate([0,20,0]) > color("orange") > my_part(); > > > translate([20,0,0]) > my_part_with_first_layer_inset(inset_width=2) > cylinder(d=20,h=2); ----- Admin - PM me if you need anything, or if I've done something stupid... Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above. The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out! -- View this message in context: http://forum.openscad.org/Passing-objects-as-arguments-tp19877p19879.html Sent from the OpenSCAD mailing list archive at Nabble.com.