Is there a functionality similar to Python's 'if name ==
"main"' which will run only if you're in the actual file, and will
be ignored if the file is include'd from another?
I have this sort of file layout:
// variables here
include <config.scad>
module part1() {
// part based on config variables
}
include <config.scad>
module part2() {
// another part based on config variables
}
I would like to see part1() rendered in the default position only when
I'm actually in part1.scad.
Once I am in render.scad, I don't want to see part1() rendered like
that, I only want to see the final "good" transformed/rotated/colored
instance of the part.
I tried a few methods like a "rendering = true/false" variable and
"use" instead of "include" but I couldn't find an automated method. I
suspect there is some solution using correct syntax which is not
immediately obvious to me.
Can this be done in some way?
Jamie
To clarify, you want to have a part1() and part2() call in each file
respectively, but don't want to have those calls made when render
include()'s them?
The use<> should have worked to do that.
Alternatively you could put this in render.scad ($variables are dynamic
scope)
$main=1;
Then in the part file
if ($main!=1) part1();
If you don't like the warning add $main=0; to the part file.
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.
Sent from: http://forum.openscad.org/
Actually there won't be a warning, unknown $variables don't get a warning...
-----Original Message-----
From: Discuss [mailto:discuss-bounces@lists.openscad.org] On Behalf Of MichaelAtOz
Sent: Wed, 29 Nov 2017 12:55
To: discuss@lists.openscad.org
Subject: Re: [OpenSCAD] "if main" functionality?
To clarify, you want to have a part1() and part2() call in each file
respectively, but don't want to have those calls made when render
include()'s them?
The use<> should have worked to do that.
Alternatively you could put this in render.scad ($variables are dynamic
scope)
$main=1;
Then in the part file
if ($main!=1) part1();
If you don't like the warning add $main=0; to the part file.
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.
Sent from: http://forum.openscad.org/
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
On 29 November 2017 at 11:54, MichaelAtOz oz.at.michael@gmail.com wrote:
To clarify, you want to have a part1() and part2() call in each file
respectively, but don't want to have those calls made when render
include()'s them?
The use<> should have worked to do that.
Ah, it actually does work. I couldn't reproduce the incorrect
behaviour when making a little reproducer from scratch. I reviewed my
part code and found I'd both use'd and include'd one of the part
files, and that was the part I was testing the render with. My
mistake. "use <part1.scad>" does exactly what I was after.
Alternatively you could put this in render.scad ($variables are dynamic
scope)
$main=1;
Then in the part file
if ($main!=1) part1();
This also works perfectly.
Thank you very much for your help!