[ Nothing to do with Terry's aliasing question. Further discussion over
on my "Volumetric color" thread, please. ]
On 2/9/2022 2:12 PM, David Schooley wrote:
Since multi-color printing came up recently without me following the
conversation too closely…
Modules can make multi-color printing easy. The part to be done in
color #1 is one module and the part done in color #2 is another
module. Part #2 is subtracted from part #1 to get the stl for the
first color, and part #2 is used by itself to get the stl for the
second color.
The reason that I thought it needed work was that you want to be able to
specify colors arbitrarily deeply nested in the design. The "head"
module needs to have flesh-colored skin, hair-colored hair, and
eye-colored eyes. And the "eye" module might have three or more colors
itself.
And then, given the "head" module, you need to extract just the
iris-colored part of the eyes into a separate STL.
You place this down near the bottom of your text file:
module unique_name(){
<put your text here... it needs to be lines of openSCAD keywords with
proper syntax, just like the lines you are copying from your existing
project>
}
Then you use "unique_name();" to instantiate code in the module.
You don't need to know any more than that, even tho there is more you can
do.
This will NOT do a simple text replacement. Everything inside the module
needs to be complete openSCAD statements as well as the code that surrounds
the instantiation.
Also, variable handling won't pass into/out of the module like a macro
would allow (in general, openSCAD variables don't behave like they do in a
software program). Perhaps this is part of why you are resistant? I admit
that I am having difficulty "seeing" with your eyes regarding this. This
suggests that there is a disconnect here that has yet to be identified (at
least WRT to my understanding, or lack thereof).
On Wed, Feb 9, 2022 at 4:49 PM jon jon@jonbondy.com wrote:
I keep thinking that you want a module(). I use them all the time, and
they are trivial to write.
On 2/9/2022 5:43 PM, terrypingm@gmail.com wrote:
Yes, that’s the sort of thing I can do with Macro Express Pro. But
like all approaches of this genre it nets down to
Which is not what I described. I want
A. The abbreviation to be created in OpenSCAD
B. Used as an alias for the code, not to reproduce it.
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
On 2/9/2022 2:43 PM, terrypingm@gmail.com wrote:
Which is not what I described. I want
A. The abbreviation to be created in OpenSCAD
B. Used as an alias for the code, not to reproduce it.
Yep.
That's exactly what modules are.
You have, say:
difference() {
cylinder(h=10, d=1, center=true);
cylinder(h=11, d=0.9, center=true);
}
You want to give that a name - say, "pipe".
module pipe() {
difference() {
cylinder(h=10, d=1, center=true);
cylinder(h=11, d=0.9, center=true);
}
}
You want to use that definition in multiple places:
pipe();
translate([10,0,0]) pipe();
This isn't quite as simple as it can possibly get, but it's close.
Any scheme that would address your need will have a few things:
The only thing that could be simpler would be if the parentheses weren't
required.
Modules can do more than this, of course, but you can use them in this
simple way and it's perfectly OK.
The only thing that I can come up with that modules can't do is to set
variables to be used later, but if you're still struggling with modules
then I don't think that's a problem for you yet.
And you are absolutely correct in not wanting to use an "automatic
typing" answer, because then if you decide that you need to make a
change, you have to somehow hunt down all of the uses and re-generate them.
"Automatic typing" might be useful if you are going to want to edit each
example so that they are different. Even then, I'd look at a
parameterized module instead.