discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Pieces of a whole

DV
david vanhorn
Mon, Mar 22, 2021 3:37 PM

I'm doing a complex design with multiple parts.
I need to be able to render and export each sub part independently.
I also need to see a cross section with all parts assembled.

I created an overview, using a boolean variable called CrossSection, and in
the sub parts, I would like to have them sectioned only if CrossSection is
true, but of course without the main file, CrossSection is undefined.

In other languages I would do something like  "If undef CrossSection then
CrossSection = false"

How can I implement this in OpenScad?

--
K1FZY (WA4TPW) SK  9/29/37-4/13/15

I'm doing a complex design with multiple parts. I need to be able to render and export each sub part independently. I also need to see a cross section with all parts assembled. I created an overview, using a boolean variable called CrossSection, and in the sub parts, I would like to have them sectioned only if CrossSection is true, but of course without the main file, CrossSection is undefined. In other languages I would do something like "If undef CrossSection then CrossSection = false" How can I implement this in OpenScad? -- K1FZY (WA4TPW) SK 9/29/37-4/13/15
NH
nop head
Mon, Mar 22, 2021 3:39 PM

if(is_undef(CrossSection) ? false : CrossSection) ...;

On Mon, 22 Mar 2021 at 15:38, david vanhorn kc6ete@gmail.com wrote:

I'm doing a complex design with multiple parts.
I need to be able to render and export each sub part independently.
I also need to see a cross section with all parts assembled.

I created an overview, using a boolean variable called CrossSection, and
in the sub parts, I would like to have them sectioned only if CrossSection
is true, but of course without the main file, CrossSection is undefined.

In other languages I would do something like  "If undef CrossSection then
CrossSection = false"

How can I implement this in OpenScad?

--
K1FZY (WA4TPW) SK  9/29/37-4/13/15


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

if(is_undef(CrossSection) ? false : CrossSection) ...; On Mon, 22 Mar 2021 at 15:38, david vanhorn <kc6ete@gmail.com> wrote: > I'm doing a complex design with multiple parts. > I need to be able to render and export each sub part independently. > I also need to see a cross section with all parts assembled. > > I created an overview, using a boolean variable called CrossSection, and > in the sub parts, I would like to have them sectioned only if CrossSection > is true, but of course without the main file, CrossSection is undefined. > > In other languages I would do something like "If undef CrossSection then > CrossSection = false" > > How can I implement this in OpenScad? > > -- > K1FZY (WA4TPW) SK 9/29/37-4/13/15 > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
DV
david vanhorn
Mon, Mar 22, 2021 3:52 PM

I'm not quite seeing it.
How would I apply it here:

module HandleFront(){
render()
difference(){
HandleFrontFull();
// I'd like to turn this element on or off based on CrossSection
HalfClip(); //
}
}// end of difference
}// end of module

So I assume that earlier in this file, I should use the if Is_undef to set
CrossSection to false, but I'm not understanding how.

On Mon, Mar 22, 2021 at 9:40 AM nop head nop.head@gmail.com wrote:

if(is_undef(CrossSection) ? false : CrossSection) ...;

On Mon, 22 Mar 2021 at 15:38, david vanhorn kc6ete@gmail.com wrote:

I'm doing a complex design with multiple parts.
I need to be able to render and export each sub part independently.
I also need to see a cross section with all parts assembled.

I created an overview, using a boolean variable called CrossSection, and
in the sub parts, I would like to have them sectioned only if CrossSection
is true, but of course without the main file, CrossSection is undefined.

In other languages I would do something like  "If undef CrossSection then
CrossSection = false"

How can I implement this in OpenScad?

--
K1FZY (WA4TPW) SK  9/29/37-4/13/15


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

--
K1FZY (WA4TPW) SK  9/29/37-4/13/15

I'm not quite seeing it. How would I apply it here: module HandleFront(){ render() difference(){ HandleFrontFull(); // I'd like to turn this element on or off based on CrossSection HalfClip(); // } }// end of difference }// end of module So I assume that earlier in this file, I should use the if Is_undef to set CrossSection to false, but I'm not understanding how. On Mon, Mar 22, 2021 at 9:40 AM nop head <nop.head@gmail.com> wrote: > if(is_undef(CrossSection) ? false : CrossSection) ...; > > On Mon, 22 Mar 2021 at 15:38, david vanhorn <kc6ete@gmail.com> wrote: > >> I'm doing a complex design with multiple parts. >> I need to be able to render and export each sub part independently. >> I also need to see a cross section with all parts assembled. >> >> I created an overview, using a boolean variable called CrossSection, and >> in the sub parts, I would like to have them sectioned only if CrossSection >> is true, but of course without the main file, CrossSection is undefined. >> >> In other languages I would do something like "If undef CrossSection then >> CrossSection = false" >> >> How can I implement this in OpenScad? >> >> -- >> K1FZY (WA4TPW) SK 9/29/37-4/13/15 >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org >> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org > -- K1FZY (WA4TPW) SK 9/29/37-4/13/15
DV
david vanhorn
Mon, Mar 22, 2021 4:31 PM

Ok, I think I have it now.
Not quite the same, but it's working for me

CrossSection = !is_undef(CrossSection);
if (false == CrossSection){
echo("Printable part generation of CH_Part_Lock");
} else {
echo("Generating cross section of CH_Part_Lock");
}

Then at the bottom of the file:

// Show the part alone if we're only running this file
if (false == CrossSection){
echo("Showing part");
TwistLockF(); // This could be printed separately
}

On Mon, Mar 22, 2021 at 9:52 AM david vanhorn kc6ete@gmail.com wrote:

I'm not quite seeing it.
How would I apply it here:

module HandleFront(){
render()
difference(){
HandleFrontFull();
// I'd like to turn this element on or off based on CrossSection
HalfClip(); //
}
}// end of difference
}// end of module

So I assume that earlier in this file, I should use the if Is_undef to set
CrossSection to false, but I'm not understanding how.

On Mon, Mar 22, 2021 at 9:40 AM nop head nop.head@gmail.com wrote:

if(is_undef(CrossSection) ? false : CrossSection) ...;

On Mon, 22 Mar 2021 at 15:38, david vanhorn kc6ete@gmail.com wrote:

I'm doing a complex design with multiple parts.
I need to be able to render and export each sub part independently.
I also need to see a cross section with all parts assembled.

I created an overview, using a boolean variable called CrossSection, and
in the sub parts, I would like to have them sectioned only if CrossSection
is true, but of course without the main file, CrossSection is undefined.

In other languages I would do something like  "If undef CrossSection
then CrossSection = false"

How can I implement this in OpenScad?

--
K1FZY (WA4TPW) SK  9/29/37-4/13/15


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

--
K1FZY (WA4TPW) SK  9/29/37-4/13/15

--
K1FZY (WA4TPW) SK  9/29/37-4/13/15

Ok, I think I have it now. Not quite the same, but it's working for me CrossSection = !is_undef(CrossSection); if (false == CrossSection){ echo("Printable part generation of CH_Part_Lock"); } else { echo("Generating cross section of CH_Part_Lock"); } Then at the bottom of the file: // Show the part alone if we're only running this file if (false == CrossSection){ echo("Showing part"); TwistLockF(); // This could be printed separately } On Mon, Mar 22, 2021 at 9:52 AM david vanhorn <kc6ete@gmail.com> wrote: > I'm not quite seeing it. > How would I apply it here: > > module HandleFront(){ > render() > difference(){ > HandleFrontFull(); > // I'd like to turn this element on or off based on CrossSection > HalfClip(); // > } > }// end of difference > }// end of module > > So I assume that earlier in this file, I should use the if Is_undef to set > CrossSection to false, but I'm not understanding how. > > > > On Mon, Mar 22, 2021 at 9:40 AM nop head <nop.head@gmail.com> wrote: > >> if(is_undef(CrossSection) ? false : CrossSection) ...; >> >> On Mon, 22 Mar 2021 at 15:38, david vanhorn <kc6ete@gmail.com> wrote: >> >>> I'm doing a complex design with multiple parts. >>> I need to be able to render and export each sub part independently. >>> I also need to see a cross section with all parts assembled. >>> >>> I created an overview, using a boolean variable called CrossSection, and >>> in the sub parts, I would like to have them sectioned only if CrossSection >>> is true, but of course without the main file, CrossSection is undefined. >>> >>> In other languages I would do something like "If undef CrossSection >>> then CrossSection = false" >>> >>> How can I implement this in OpenScad? >>> >>> -- >>> K1FZY (WA4TPW) SK 9/29/37-4/13/15 >>> _______________________________________________ >>> OpenSCAD mailing list >>> To unsubscribe send an email to discuss-leave@lists.openscad.org >>> >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org >> > > > -- > K1FZY (WA4TPW) SK 9/29/37-4/13/15 > -- K1FZY (WA4TPW) SK 9/29/37-4/13/15
DV
david vanhorn
Mon, Mar 22, 2021 5:10 PM

Well.. I thought I understood it..

// If we're running this file without calling it from the top level file,
then CrossSection is undefined.

if (is_undef(CrossSection)){
CrossSection = false; // So set it to false
}

// Now use echos to check that CrossSection has been set
if (is_undef(CrossSection)){
echo("CrossSection is undefined");
}
if (false == CrossSection){
echo("CrossSection is false");
}
if (true==CrossSection){
echo("CrossSection is true");
}

Output:

ECHO:"CrossSection is undefined"

On Mon, Mar 22, 2021 at 10:31 AM david vanhorn kc6ete@gmail.com wrote:

Ok, I think I have it now.
Not quite the same, but it's working for me

CrossSection = !is_undef(CrossSection);
if (false == CrossSection){
echo("Printable part generation of CH_Part_Lock");
} else {
echo("Generating cross section of CH_Part_Lock");
}

Then at the bottom of the file:

// Show the part alone if we're only running this file
if (false == CrossSection){
echo("Showing part");
TwistLockF(); // This could be printed separately
}

On Mon, Mar 22, 2021 at 9:52 AM david vanhorn kc6ete@gmail.com wrote:

I'm not quite seeing it.
How would I apply it here:

module HandleFront(){
render()
difference(){
HandleFrontFull();
// I'd like to turn this element on or off based on CrossSection
HalfClip(); //
}
}// end of difference
}// end of module

So I assume that earlier in this file, I should use the if Is_undef to
set CrossSection to false, but I'm not understanding how.

On Mon, Mar 22, 2021 at 9:40 AM nop head nop.head@gmail.com wrote:

if(is_undef(CrossSection) ? false : CrossSection) ...;

On Mon, 22 Mar 2021 at 15:38, david vanhorn kc6ete@gmail.com wrote:

I'm doing a complex design with multiple parts.
I need to be able to render and export each sub part independently.
I also need to see a cross section with all parts assembled.

I created an overview, using a boolean variable called CrossSection,
and in the sub parts, I would like to have them sectioned only if
CrossSection is true, but of course without the main file, CrossSection is
undefined.

In other languages I would do something like  "If undef CrossSection
then CrossSection = false"

How can I implement this in OpenScad?

--
K1FZY (WA4TPW) SK  9/29/37-4/13/15


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

--
K1FZY (WA4TPW) SK  9/29/37-4/13/15

--
K1FZY (WA4TPW) SK  9/29/37-4/13/15

--
K1FZY (WA4TPW) SK  9/29/37-4/13/15

Well.. I thought I understood it.. // If we're running this file without calling it from the top level file, then CrossSection is undefined. if (is_undef(CrossSection)){ CrossSection = false; // So set it to false } // Now use echos to check that CrossSection has been set if (is_undef(CrossSection)){ echo("CrossSection is undefined"); } if (false == CrossSection){ echo("CrossSection is false"); } if (true==CrossSection){ echo("CrossSection is true"); } Output: ECHO:"CrossSection is undefined" On Mon, Mar 22, 2021 at 10:31 AM david vanhorn <kc6ete@gmail.com> wrote: > Ok, I think I have it now. > Not quite the same, but it's working for me > > CrossSection = !is_undef(CrossSection); > if (false == CrossSection){ > echo("Printable part generation of CH_Part_Lock"); > } else { > echo("Generating cross section of CH_Part_Lock"); > } > > Then at the bottom of the file: > > // Show the part alone if we're only running this file > if (false == CrossSection){ > echo("Showing part"); > TwistLockF(); // This could be printed separately > } > > On Mon, Mar 22, 2021 at 9:52 AM david vanhorn <kc6ete@gmail.com> wrote: > >> I'm not quite seeing it. >> How would I apply it here: >> >> module HandleFront(){ >> render() >> difference(){ >> HandleFrontFull(); >> // I'd like to turn this element on or off based on CrossSection >> HalfClip(); // >> } >> }// end of difference >> }// end of module >> >> So I assume that earlier in this file, I should use the if Is_undef to >> set CrossSection to false, but I'm not understanding how. >> >> >> >> On Mon, Mar 22, 2021 at 9:40 AM nop head <nop.head@gmail.com> wrote: >> >>> if(is_undef(CrossSection) ? false : CrossSection) ...; >>> >>> On Mon, 22 Mar 2021 at 15:38, david vanhorn <kc6ete@gmail.com> wrote: >>> >>>> I'm doing a complex design with multiple parts. >>>> I need to be able to render and export each sub part independently. >>>> I also need to see a cross section with all parts assembled. >>>> >>>> I created an overview, using a boolean variable called CrossSection, >>>> and in the sub parts, I would like to have them sectioned only if >>>> CrossSection is true, but of course without the main file, CrossSection is >>>> undefined. >>>> >>>> In other languages I would do something like "If undef CrossSection >>>> then CrossSection = false" >>>> >>>> How can I implement this in OpenScad? >>>> >>>> -- >>>> K1FZY (WA4TPW) SK 9/29/37-4/13/15 >>>> _______________________________________________ >>>> OpenSCAD mailing list >>>> To unsubscribe send an email to discuss-leave@lists.openscad.org >>>> >>> _______________________________________________ >>> OpenSCAD mailing list >>> To unsubscribe send an email to discuss-leave@lists.openscad.org >>> >> >> >> -- >> K1FZY (WA4TPW) SK 9/29/37-4/13/15 >> > > > -- > K1FZY (WA4TPW) SK 9/29/37-4/13/15 > -- K1FZY (WA4TPW) SK 9/29/37-4/13/15
AC
A. Craig West
Mon, Mar 22, 2021 5:21 PM

The general consensus amongst programmers is that using global variables is
rarely a good idea, the easiest and most understandable way to do this is
by adding CrossSection as an argument to the module...

On Mon, Mar 22, 2021 at 1:10 PM david vanhorn kc6ete@gmail.com wrote:

Well.. I thought I understood it..

// If we're running this file without calling it from the top level file,
then CrossSection is undefined.

if (is_undef(CrossSection)){
CrossSection = false; // So set it to false
}

// Now use echos to check that CrossSection has been set
if (is_undef(CrossSection)){
echo("CrossSection is undefined");
}
if (false == CrossSection){
echo("CrossSection is false");
}
if (true==CrossSection){
echo("CrossSection is true");
}

Output:

ECHO:"CrossSection is undefined"

On Mon, Mar 22, 2021 at 10:31 AM david vanhorn kc6ete@gmail.com wrote:

Ok, I think I have it now.
Not quite the same, but it's working for me

CrossSection = !is_undef(CrossSection);
if (false == CrossSection){
echo("Printable part generation of CH_Part_Lock");
} else {
echo("Generating cross section of CH_Part_Lock");
}

Then at the bottom of the file:

// Show the part alone if we're only running this file
if (false == CrossSection){
echo("Showing part");
TwistLockF(); // This could be printed separately
}

On Mon, Mar 22, 2021 at 9:52 AM david vanhorn kc6ete@gmail.com wrote:

I'm not quite seeing it.
How would I apply it here:

module HandleFront(){
render()
difference(){
HandleFrontFull();
// I'd like to turn this element on or off based on CrossSection
HalfClip(); //
}
}// end of difference
}// end of module

So I assume that earlier in this file, I should use the if Is_undef to
set CrossSection to false, but I'm not understanding how.

On Mon, Mar 22, 2021 at 9:40 AM nop head nop.head@gmail.com wrote:

if(is_undef(CrossSection) ? false : CrossSection) ...;

On Mon, 22 Mar 2021 at 15:38, david vanhorn kc6ete@gmail.com wrote:

I'm doing a complex design with multiple parts.
I need to be able to render and export each sub part independently.
I also need to see a cross section with all parts assembled.

I created an overview, using a boolean variable called CrossSection,
and in the sub parts, I would like to have them sectioned only if
CrossSection is true, but of course without the main file, CrossSection is
undefined.

In other languages I would do something like  "If undef CrossSection
then CrossSection = false"

How can I implement this in OpenScad?

--
K1FZY (WA4TPW) SK  9/29/37-4/13/15


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

--
K1FZY (WA4TPW) SK  9/29/37-4/13/15

--
K1FZY (WA4TPW) SK  9/29/37-4/13/15

--
K1FZY (WA4TPW) SK  9/29/37-4/13/15


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

The general consensus amongst programmers is that using global variables is rarely a good idea, the easiest and most understandable way to do this is by adding CrossSection as an argument to the module... On Mon, Mar 22, 2021 at 1:10 PM david vanhorn <kc6ete@gmail.com> wrote: > Well.. I thought I understood it.. > > // If we're running this file without calling it from the top level file, > then CrossSection is undefined. > > if (is_undef(CrossSection)){ > CrossSection = false; // So set it to false > } > > // Now use echos to check that CrossSection has been set > if (is_undef(CrossSection)){ > echo("CrossSection is undefined"); > } > if (false == CrossSection){ > echo("CrossSection is false"); > } > if (true==CrossSection){ > echo("CrossSection is true"); > } > > > Output: > > ECHO:"CrossSection is undefined" > > On Mon, Mar 22, 2021 at 10:31 AM david vanhorn <kc6ete@gmail.com> wrote: > >> Ok, I think I have it now. >> Not quite the same, but it's working for me >> >> CrossSection = !is_undef(CrossSection); >> if (false == CrossSection){ >> echo("Printable part generation of CH_Part_Lock"); >> } else { >> echo("Generating cross section of CH_Part_Lock"); >> } >> >> Then at the bottom of the file: >> >> // Show the part alone if we're only running this file >> if (false == CrossSection){ >> echo("Showing part"); >> TwistLockF(); // This could be printed separately >> } >> >> On Mon, Mar 22, 2021 at 9:52 AM david vanhorn <kc6ete@gmail.com> wrote: >> >>> I'm not quite seeing it. >>> How would I apply it here: >>> >>> module HandleFront(){ >>> render() >>> difference(){ >>> HandleFrontFull(); >>> // I'd like to turn this element on or off based on CrossSection >>> HalfClip(); // >>> } >>> }// end of difference >>> }// end of module >>> >>> So I assume that earlier in this file, I should use the if Is_undef to >>> set CrossSection to false, but I'm not understanding how. >>> >>> >>> >>> On Mon, Mar 22, 2021 at 9:40 AM nop head <nop.head@gmail.com> wrote: >>> >>>> if(is_undef(CrossSection) ? false : CrossSection) ...; >>>> >>>> On Mon, 22 Mar 2021 at 15:38, david vanhorn <kc6ete@gmail.com> wrote: >>>> >>>>> I'm doing a complex design with multiple parts. >>>>> I need to be able to render and export each sub part independently. >>>>> I also need to see a cross section with all parts assembled. >>>>> >>>>> I created an overview, using a boolean variable called CrossSection, >>>>> and in the sub parts, I would like to have them sectioned only if >>>>> CrossSection is true, but of course without the main file, CrossSection is >>>>> undefined. >>>>> >>>>> In other languages I would do something like "If undef CrossSection >>>>> then CrossSection = false" >>>>> >>>>> How can I implement this in OpenScad? >>>>> >>>>> -- >>>>> K1FZY (WA4TPW) SK 9/29/37-4/13/15 >>>>> _______________________________________________ >>>>> OpenSCAD mailing list >>>>> To unsubscribe send an email to discuss-leave@lists.openscad.org >>>>> >>>> _______________________________________________ >>>> OpenSCAD mailing list >>>> To unsubscribe send an email to discuss-leave@lists.openscad.org >>>> >>> >>> >>> -- >>> K1FZY (WA4TPW) SK 9/29/37-4/13/15 >>> >> >> >> -- >> K1FZY (WA4TPW) SK 9/29/37-4/13/15 >> > > > -- > K1FZY (WA4TPW) SK 9/29/37-4/13/15 > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
NH
nop head
Mon, Mar 22, 2021 5:23 PM

You can't change variables in OpenSCAD.

if (is_undef(CrossSection)){
CrossSection = false; // So set it to false
}

Simply creates a new variable: CrossSection, that only exists between the
braces.

You can create a new variable. Like this.

DoSection = !is_undef(CrossSection) && CrossSection;

Or you could use a function.

function CrossSection() = !is_undef(CrossSection) && CrossSection;

Then do:

if(CrossSection()) {
...
}

On Mon, 22 Mar 2021 at 17:10, david vanhorn kc6ete@gmail.com wrote:

Well.. I thought I understood it..

// If we're running this file without calling it from the top level file,
then CrossSection is undefined.

if (is_undef(CrossSection)){
CrossSection = false; // So set it to false
}

// Now use echos to check that CrossSection has been set
if (is_undef(CrossSection)){
echo("CrossSection is undefined");
}
if (false == CrossSection){
echo("CrossSection is false");
}
if (true==CrossSection){
echo("CrossSection is true");
}

Output:

ECHO:"CrossSection is undefined"

On Mon, Mar 22, 2021 at 10:31 AM david vanhorn kc6ete@gmail.com wrote:

Ok, I think I have it now.
Not quite the same, but it's working for me

CrossSection = !is_undef(CrossSection);
if (false == CrossSection){
echo("Printable part generation of CH_Part_Lock");
} else {
echo("Generating cross section of CH_Part_Lock");
}

Then at the bottom of the file:

// Show the part alone if we're only running this file
if (false == CrossSection){
echo("Showing part");
TwistLockF(); // This could be printed separately
}

On Mon, Mar 22, 2021 at 9:52 AM david vanhorn kc6ete@gmail.com wrote:

I'm not quite seeing it.
How would I apply it here:

module HandleFront(){
render()
difference(){
HandleFrontFull();
// I'd like to turn this element on or off based on CrossSection
HalfClip(); //
}
}// end of difference
}// end of module

So I assume that earlier in this file, I should use the if Is_undef to
set CrossSection to false, but I'm not understanding how.

On Mon, Mar 22, 2021 at 9:40 AM nop head nop.head@gmail.com wrote:

if(is_undef(CrossSection) ? false : CrossSection) ...;

On Mon, 22 Mar 2021 at 15:38, david vanhorn kc6ete@gmail.com wrote:

I'm doing a complex design with multiple parts.
I need to be able to render and export each sub part independently.
I also need to see a cross section with all parts assembled.

I created an overview, using a boolean variable called CrossSection,
and in the sub parts, I would like to have them sectioned only if
CrossSection is true, but of course without the main file, CrossSection is
undefined.

In other languages I would do something like  "If undef CrossSection
then CrossSection = false"

How can I implement this in OpenScad?

--
K1FZY (WA4TPW) SK  9/29/37-4/13/15


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

--
K1FZY (WA4TPW) SK  9/29/37-4/13/15

--
K1FZY (WA4TPW) SK  9/29/37-4/13/15

--
K1FZY (WA4TPW) SK  9/29/37-4/13/15


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

You can't change variables in OpenSCAD. if (is_undef(CrossSection)){ CrossSection = false; // So set it to false } Simply creates a new variable: CrossSection, that only exists between the braces. You can create a new variable. Like this. DoSection = !is_undef(CrossSection) && CrossSection; Or you could use a function. function CrossSection() = !is_undef(CrossSection) && CrossSection; Then do: if(CrossSection()) { ... } On Mon, 22 Mar 2021 at 17:10, david vanhorn <kc6ete@gmail.com> wrote: > Well.. I thought I understood it.. > > // If we're running this file without calling it from the top level file, > then CrossSection is undefined. > > if (is_undef(CrossSection)){ > CrossSection = false; // So set it to false > } > > // Now use echos to check that CrossSection has been set > if (is_undef(CrossSection)){ > echo("CrossSection is undefined"); > } > if (false == CrossSection){ > echo("CrossSection is false"); > } > if (true==CrossSection){ > echo("CrossSection is true"); > } > > > Output: > > ECHO:"CrossSection is undefined" > > On Mon, Mar 22, 2021 at 10:31 AM david vanhorn <kc6ete@gmail.com> wrote: > >> Ok, I think I have it now. >> Not quite the same, but it's working for me >> >> CrossSection = !is_undef(CrossSection); >> if (false == CrossSection){ >> echo("Printable part generation of CH_Part_Lock"); >> } else { >> echo("Generating cross section of CH_Part_Lock"); >> } >> >> Then at the bottom of the file: >> >> // Show the part alone if we're only running this file >> if (false == CrossSection){ >> echo("Showing part"); >> TwistLockF(); // This could be printed separately >> } >> >> On Mon, Mar 22, 2021 at 9:52 AM david vanhorn <kc6ete@gmail.com> wrote: >> >>> I'm not quite seeing it. >>> How would I apply it here: >>> >>> module HandleFront(){ >>> render() >>> difference(){ >>> HandleFrontFull(); >>> // I'd like to turn this element on or off based on CrossSection >>> HalfClip(); // >>> } >>> }// end of difference >>> }// end of module >>> >>> So I assume that earlier in this file, I should use the if Is_undef to >>> set CrossSection to false, but I'm not understanding how. >>> >>> >>> >>> On Mon, Mar 22, 2021 at 9:40 AM nop head <nop.head@gmail.com> wrote: >>> >>>> if(is_undef(CrossSection) ? false : CrossSection) ...; >>>> >>>> On Mon, 22 Mar 2021 at 15:38, david vanhorn <kc6ete@gmail.com> wrote: >>>> >>>>> I'm doing a complex design with multiple parts. >>>>> I need to be able to render and export each sub part independently. >>>>> I also need to see a cross section with all parts assembled. >>>>> >>>>> I created an overview, using a boolean variable called CrossSection, >>>>> and in the sub parts, I would like to have them sectioned only if >>>>> CrossSection is true, but of course without the main file, CrossSection is >>>>> undefined. >>>>> >>>>> In other languages I would do something like "If undef CrossSection >>>>> then CrossSection = false" >>>>> >>>>> How can I implement this in OpenScad? >>>>> >>>>> -- >>>>> K1FZY (WA4TPW) SK 9/29/37-4/13/15 >>>>> _______________________________________________ >>>>> OpenSCAD mailing list >>>>> To unsubscribe send an email to discuss-leave@lists.openscad.org >>>>> >>>> _______________________________________________ >>>> OpenSCAD mailing list >>>> To unsubscribe send an email to discuss-leave@lists.openscad.org >>>> >>> >>> >>> -- >>> K1FZY (WA4TPW) SK 9/29/37-4/13/15 >>> >> >> >> -- >> K1FZY (WA4TPW) SK 9/29/37-4/13/15 >> > > > -- > K1FZY (WA4TPW) SK 9/29/37-4/13/15 > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
DV
david vanhorn
Mon, Mar 22, 2021 5:26 PM

I knew you couldn't change variables, but I didn't think that assigning one
which was undefined was "changing" it.

On Mon, Mar 22, 2021 at 11:25 AM nop head nop.head@gmail.com wrote:

You can't change variables in OpenSCAD.

if (is_undef(CrossSection)){
CrossSection = false; // So set it to false
}

Simply creates a new variable: CrossSection, that only exists between the
braces.

You can create a new variable. Like this.

DoSection = !is_undef(CrossSection) && CrossSection;

Or you could use a function.

function CrossSection() = !is_undef(CrossSection) && CrossSection;

Then do:

if(CrossSection()) {
...
}

On Mon, 22 Mar 2021 at 17:10, david vanhorn kc6ete@gmail.com wrote:

Well.. I thought I understood it..

// If we're running this file without calling it from the top level file,
then CrossSection is undefined.

if (is_undef(CrossSection)){
CrossSection = false; // So set it to false
}

// Now use echos to check that CrossSection has been set
if (is_undef(CrossSection)){
echo("CrossSection is undefined");
}
if (false == CrossSection){
echo("CrossSection is false");
}
if (true==CrossSection){
echo("CrossSection is true");
}

Output:

ECHO:"CrossSection is undefined"

On Mon, Mar 22, 2021 at 10:31 AM david vanhorn kc6ete@gmail.com wrote:

Ok, I think I have it now.
Not quite the same, but it's working for me

CrossSection = !is_undef(CrossSection);
if (false == CrossSection){
echo("Printable part generation of CH_Part_Lock");
} else {
echo("Generating cross section of CH_Part_Lock");
}

Then at the bottom of the file:

// Show the part alone if we're only running this file
if (false == CrossSection){
echo("Showing part");
TwistLockF(); // This could be printed separately
}

On Mon, Mar 22, 2021 at 9:52 AM david vanhorn kc6ete@gmail.com wrote:

I'm not quite seeing it.
How would I apply it here:

module HandleFront(){
render()
difference(){
HandleFrontFull();
// I'd like to turn this element on or off based on CrossSection
HalfClip(); //
}
}// end of difference
}// end of module

So I assume that earlier in this file, I should use the if Is_undef to
set CrossSection to false, but I'm not understanding how.

On Mon, Mar 22, 2021 at 9:40 AM nop head nop.head@gmail.com wrote:

if(is_undef(CrossSection) ? false : CrossSection) ...;

On Mon, 22 Mar 2021 at 15:38, david vanhorn kc6ete@gmail.com wrote:

I'm doing a complex design with multiple parts.
I need to be able to render and export each sub part independently.
I also need to see a cross section with all parts assembled.

I created an overview, using a boolean variable called CrossSection,
and in the sub parts, I would like to have them sectioned only if
CrossSection is true, but of course without the main file, CrossSection is
undefined.

In other languages I would do something like  "If undef CrossSection
then CrossSection = false"

How can I implement this in OpenScad?

--
K1FZY (WA4TPW) SK  9/29/37-4/13/15


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

--
K1FZY (WA4TPW) SK  9/29/37-4/13/15

--
K1FZY (WA4TPW) SK  9/29/37-4/13/15

--
K1FZY (WA4TPW) SK  9/29/37-4/13/15


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

--
K1FZY (WA4TPW) SK  9/29/37-4/13/15

I knew you couldn't change variables, but I didn't think that assigning one which was undefined was "changing" it. On Mon, Mar 22, 2021 at 11:25 AM nop head <nop.head@gmail.com> wrote: > You can't change variables in OpenSCAD. > > if (is_undef(CrossSection)){ > CrossSection = false; // So set it to false > } > > Simply creates a new variable: CrossSection, that only exists between the > braces. > > You can create a new variable. Like this. > > DoSection = !is_undef(CrossSection) && CrossSection; > > Or you could use a function. > > function CrossSection() = !is_undef(CrossSection) && CrossSection; > > Then do: > > if(CrossSection()) { > ... > } > > > > > > On Mon, 22 Mar 2021 at 17:10, david vanhorn <kc6ete@gmail.com> wrote: > >> Well.. I thought I understood it.. >> >> // If we're running this file without calling it from the top level file, >> then CrossSection is undefined. >> >> if (is_undef(CrossSection)){ >> CrossSection = false; // So set it to false >> } >> >> // Now use echos to check that CrossSection has been set >> if (is_undef(CrossSection)){ >> echo("CrossSection is undefined"); >> } >> if (false == CrossSection){ >> echo("CrossSection is false"); >> } >> if (true==CrossSection){ >> echo("CrossSection is true"); >> } >> >> >> Output: >> >> ECHO:"CrossSection is undefined" >> >> On Mon, Mar 22, 2021 at 10:31 AM david vanhorn <kc6ete@gmail.com> wrote: >> >>> Ok, I think I have it now. >>> Not quite the same, but it's working for me >>> >>> CrossSection = !is_undef(CrossSection); >>> if (false == CrossSection){ >>> echo("Printable part generation of CH_Part_Lock"); >>> } else { >>> echo("Generating cross section of CH_Part_Lock"); >>> } >>> >>> Then at the bottom of the file: >>> >>> // Show the part alone if we're only running this file >>> if (false == CrossSection){ >>> echo("Showing part"); >>> TwistLockF(); // This could be printed separately >>> } >>> >>> On Mon, Mar 22, 2021 at 9:52 AM david vanhorn <kc6ete@gmail.com> wrote: >>> >>>> I'm not quite seeing it. >>>> How would I apply it here: >>>> >>>> module HandleFront(){ >>>> render() >>>> difference(){ >>>> HandleFrontFull(); >>>> // I'd like to turn this element on or off based on CrossSection >>>> HalfClip(); // >>>> } >>>> }// end of difference >>>> }// end of module >>>> >>>> So I assume that earlier in this file, I should use the if Is_undef to >>>> set CrossSection to false, but I'm not understanding how. >>>> >>>> >>>> >>>> On Mon, Mar 22, 2021 at 9:40 AM nop head <nop.head@gmail.com> wrote: >>>> >>>>> if(is_undef(CrossSection) ? false : CrossSection) ...; >>>>> >>>>> On Mon, 22 Mar 2021 at 15:38, david vanhorn <kc6ete@gmail.com> wrote: >>>>> >>>>>> I'm doing a complex design with multiple parts. >>>>>> I need to be able to render and export each sub part independently. >>>>>> I also need to see a cross section with all parts assembled. >>>>>> >>>>>> I created an overview, using a boolean variable called CrossSection, >>>>>> and in the sub parts, I would like to have them sectioned only if >>>>>> CrossSection is true, but of course without the main file, CrossSection is >>>>>> undefined. >>>>>> >>>>>> In other languages I would do something like "If undef CrossSection >>>>>> then CrossSection = false" >>>>>> >>>>>> How can I implement this in OpenScad? >>>>>> >>>>>> -- >>>>>> K1FZY (WA4TPW) SK 9/29/37-4/13/15 >>>>>> _______________________________________________ >>>>>> OpenSCAD mailing list >>>>>> To unsubscribe send an email to discuss-leave@lists.openscad.org >>>>>> >>>>> _______________________________________________ >>>>> OpenSCAD mailing list >>>>> To unsubscribe send an email to discuss-leave@lists.openscad.org >>>>> >>>> >>>> >>>> -- >>>> K1FZY (WA4TPW) SK 9/29/37-4/13/15 >>>> >>> >>> >>> -- >>> K1FZY (WA4TPW) SK 9/29/37-4/13/15 >>> >> >> >> -- >> K1FZY (WA4TPW) SK 9/29/37-4/13/15 >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org >> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org > -- K1FZY (WA4TPW) SK 9/29/37-4/13/15
NH
nop head
Mon, Mar 22, 2021 5:51 PM

It isn't changing it, it defines a new one, but if you do it with if() it
only lasts for the scope of the if construct.

On Mon, 22 Mar 2021 at 17:26, david vanhorn kc6ete@gmail.com wrote:

I knew you couldn't change variables, but I didn't think that assigning
one which was undefined was "changing" it.

On Mon, Mar 22, 2021 at 11:25 AM nop head nop.head@gmail.com wrote:

You can't change variables in OpenSCAD.

if (is_undef(CrossSection)){
CrossSection = false; // So set it to false
}

Simply creates a new variable: CrossSection, that only exists between the
braces.

You can create a new variable. Like this.

DoSection = !is_undef(CrossSection) && CrossSection;

Or you could use a function.

function CrossSection() = !is_undef(CrossSection) && CrossSection;

Then do:

if(CrossSection()) {
...
}

On Mon, 22 Mar 2021 at 17:10, david vanhorn kc6ete@gmail.com wrote:

Well.. I thought I understood it..

// If we're running this file without calling it from the top level
file, then CrossSection is undefined.

if (is_undef(CrossSection)){
CrossSection = false; // So set it to false
}

// Now use echos to check that CrossSection has been set
if (is_undef(CrossSection)){
echo("CrossSection is undefined");
}
if (false == CrossSection){
echo("CrossSection is false");
}
if (true==CrossSection){
echo("CrossSection is true");
}

Output:

ECHO:"CrossSection is undefined"

On Mon, Mar 22, 2021 at 10:31 AM david vanhorn kc6ete@gmail.com wrote:

Ok, I think I have it now.
Not quite the same, but it's working for me

CrossSection = !is_undef(CrossSection);
if (false == CrossSection){
echo("Printable part generation of CH_Part_Lock");
} else {
echo("Generating cross section of CH_Part_Lock");
}

Then at the bottom of the file:

// Show the part alone if we're only running this file
if (false == CrossSection){
echo("Showing part");
TwistLockF(); // This could be printed separately
}

On Mon, Mar 22, 2021 at 9:52 AM david vanhorn kc6ete@gmail.com wrote:

I'm not quite seeing it.
How would I apply it here:

module HandleFront(){
render()
difference(){
HandleFrontFull();
// I'd like to turn this element on or off based on CrossSection
HalfClip(); //
}
}// end of difference
}// end of module

So I assume that earlier in this file, I should use the if Is_undef to
set CrossSection to false, but I'm not understanding how.

On Mon, Mar 22, 2021 at 9:40 AM nop head nop.head@gmail.com wrote:

if(is_undef(CrossSection) ? false : CrossSection) ...;

On Mon, 22 Mar 2021 at 15:38, david vanhorn kc6ete@gmail.com wrote:

I'm doing a complex design with multiple parts.
I need to be able to render and export each sub part independently.
I also need to see a cross section with all parts assembled.

I created an overview, using a boolean variable called CrossSection,
and in the sub parts, I would like to have them sectioned only if
CrossSection is true, but of course without the main file, CrossSection is
undefined.

In other languages I would do something like  "If undef CrossSection
then CrossSection = false"

How can I implement this in OpenScad?

--
K1FZY (WA4TPW) SK  9/29/37-4/13/15


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

--
K1FZY (WA4TPW) SK  9/29/37-4/13/15

--
K1FZY (WA4TPW) SK  9/29/37-4/13/15

--
K1FZY (WA4TPW) SK  9/29/37-4/13/15


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

--
K1FZY (WA4TPW) SK  9/29/37-4/13/15


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

It isn't changing it, it defines a new one, but if you do it with if() it only lasts for the scope of the if construct. On Mon, 22 Mar 2021 at 17:26, david vanhorn <kc6ete@gmail.com> wrote: > I knew you couldn't change variables, but I didn't think that assigning > one which was undefined was "changing" it. > > > On Mon, Mar 22, 2021 at 11:25 AM nop head <nop.head@gmail.com> wrote: > >> You can't change variables in OpenSCAD. >> >> if (is_undef(CrossSection)){ >> CrossSection = false; // So set it to false >> } >> >> Simply creates a new variable: CrossSection, that only exists between the >> braces. >> >> You can create a new variable. Like this. >> >> DoSection = !is_undef(CrossSection) && CrossSection; >> >> Or you could use a function. >> >> function CrossSection() = !is_undef(CrossSection) && CrossSection; >> >> Then do: >> >> if(CrossSection()) { >> ... >> } >> >> >> >> >> >> On Mon, 22 Mar 2021 at 17:10, david vanhorn <kc6ete@gmail.com> wrote: >> >>> Well.. I thought I understood it.. >>> >>> // If we're running this file without calling it from the top level >>> file, then CrossSection is undefined. >>> >>> if (is_undef(CrossSection)){ >>> CrossSection = false; // So set it to false >>> } >>> >>> // Now use echos to check that CrossSection has been set >>> if (is_undef(CrossSection)){ >>> echo("CrossSection is undefined"); >>> } >>> if (false == CrossSection){ >>> echo("CrossSection is false"); >>> } >>> if (true==CrossSection){ >>> echo("CrossSection is true"); >>> } >>> >>> >>> Output: >>> >>> ECHO:"CrossSection is undefined" >>> >>> On Mon, Mar 22, 2021 at 10:31 AM david vanhorn <kc6ete@gmail.com> wrote: >>> >>>> Ok, I think I have it now. >>>> Not quite the same, but it's working for me >>>> >>>> CrossSection = !is_undef(CrossSection); >>>> if (false == CrossSection){ >>>> echo("Printable part generation of CH_Part_Lock"); >>>> } else { >>>> echo("Generating cross section of CH_Part_Lock"); >>>> } >>>> >>>> Then at the bottom of the file: >>>> >>>> // Show the part alone if we're only running this file >>>> if (false == CrossSection){ >>>> echo("Showing part"); >>>> TwistLockF(); // This could be printed separately >>>> } >>>> >>>> On Mon, Mar 22, 2021 at 9:52 AM david vanhorn <kc6ete@gmail.com> wrote: >>>> >>>>> I'm not quite seeing it. >>>>> How would I apply it here: >>>>> >>>>> module HandleFront(){ >>>>> render() >>>>> difference(){ >>>>> HandleFrontFull(); >>>>> // I'd like to turn this element on or off based on CrossSection >>>>> HalfClip(); // >>>>> } >>>>> }// end of difference >>>>> }// end of module >>>>> >>>>> So I assume that earlier in this file, I should use the if Is_undef to >>>>> set CrossSection to false, but I'm not understanding how. >>>>> >>>>> >>>>> >>>>> On Mon, Mar 22, 2021 at 9:40 AM nop head <nop.head@gmail.com> wrote: >>>>> >>>>>> if(is_undef(CrossSection) ? false : CrossSection) ...; >>>>>> >>>>>> On Mon, 22 Mar 2021 at 15:38, david vanhorn <kc6ete@gmail.com> wrote: >>>>>> >>>>>>> I'm doing a complex design with multiple parts. >>>>>>> I need to be able to render and export each sub part independently. >>>>>>> I also need to see a cross section with all parts assembled. >>>>>>> >>>>>>> I created an overview, using a boolean variable called CrossSection, >>>>>>> and in the sub parts, I would like to have them sectioned only if >>>>>>> CrossSection is true, but of course without the main file, CrossSection is >>>>>>> undefined. >>>>>>> >>>>>>> In other languages I would do something like "If undef CrossSection >>>>>>> then CrossSection = false" >>>>>>> >>>>>>> How can I implement this in OpenScad? >>>>>>> >>>>>>> -- >>>>>>> K1FZY (WA4TPW) SK 9/29/37-4/13/15 >>>>>>> _______________________________________________ >>>>>>> OpenSCAD mailing list >>>>>>> To unsubscribe send an email to discuss-leave@lists.openscad.org >>>>>>> >>>>>> _______________________________________________ >>>>>> OpenSCAD mailing list >>>>>> To unsubscribe send an email to discuss-leave@lists.openscad.org >>>>>> >>>>> >>>>> >>>>> -- >>>>> K1FZY (WA4TPW) SK 9/29/37-4/13/15 >>>>> >>>> >>>> >>>> -- >>>> K1FZY (WA4TPW) SK 9/29/37-4/13/15 >>>> >>> >>> >>> -- >>> K1FZY (WA4TPW) SK 9/29/37-4/13/15 >>> _______________________________________________ >>> OpenSCAD mailing list >>> To unsubscribe send an email to discuss-leave@lists.openscad.org >>> >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org >> > > > -- > K1FZY (WA4TPW) SK 9/29/37-4/13/15 > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
JB
Jordan Brown
Mon, Mar 22, 2021 5:52 PM

On 3/22/2021 10:10 AM, david vanhorn wrote:

Well.. I thought I understood it..

// If we're running this file without calling it from the top level
file, then CrossSection is undefined.

if (is_undef(CrossSection)){
CrossSection = false; // So set it to false
}

No, that would only set CrossSection for that one block.

Once a name has a value defined in a particular block, you can't change
that value - and the top level is a block.  At one particular block
level, there is no variation that will let you optionally set a name to
a value at point A, and then later at point B set it to a default value
if it wasn't set at A.  Can't be done.

Here's a few variations that work.  (Spoiler:  I wouldn't use any of
these; see below.)

A)  Test for undef at time of use.

module part1() {
    if (!is_undef(CrossSection) && CrossSection) {
        ... whatever ...
    }
}

B)  Define a function, and call it when you need the answer.

function shouldCrossSection( ) = is_undef(CrossSection) ? false : CrossSection;

module part1() {
    if (shouldCrossSection()) {
        ... whatever ...
    }
}

C)  Define a second name at the top level, or inside a block for use in
that block.

shouldCrossSection = is_undef(CrossSection) ? false : CrossSection;

if (shouldCrossSection) {
    ... whatever ...
}

D)  Define a new variable with the same name, inside a block, for use in
that block.

module part1() {
    CrossSection = is_undef(CrossSection) ? false : CrossSection;
    if (CrossSection) {
        ... whatever ...
    }
}

Note that this is not *changing* the value of the variable; it is
creating a new variable inside this block.

But none of those is what I would do.  They all use a global variable,
lexically scoped.  It's not quite correct to say that you're stuck with
it across your entire model, but it's close.  Also, they don't work
across "use <foo.scad>"; they only work across "include <foo.scad>", and
for a lot of purposes "use" is better because it hides the details of
one file from the other.

I would use a $ variable, so that it's dynamically scoped.  I'd still
use a function to test it.  The result would be sort of like

function shouldCrossSection() = is_undef($CrossSection) ? false : $CrossSection;

module part1() {
    if (shouldCrossSection()) {
        ... do whatever ...
    }
}
module part2() {
    if (shouldCrossSection()) {
        ... do whatever ...
    }
}
module part3() {
    if (shouldCrossSection()) {
        ... do whatever ...
    }
}

and then you could do

$CrossSection = true;
part1();
part2();
part3();

and all three parts would be cross-sectioned, or you could do

part1($CrossSection=true);
part2($CrossSection=false);
part3();

and only part1 would be cross-sectioned.  Since false is the default,
part3() doesn't get cross-sectioned.

On 3/22/2021 10:10 AM, david vanhorn wrote: > Well.. I thought I understood it.. > > // If we're running this file without calling it from the top level > file, then CrossSection is undefined. > > if (is_undef(CrossSection)){ > CrossSection = false; // So set it to false > } No, that would only set CrossSection for that one block. Once a name has a value defined in a particular block, you can't change that value - and the top level is a block.  At one particular block level, there is no variation that will let you optionally set a name to a value at point A, and then later at point B set it to a default value if it wasn't set at A.  Can't be done. Here's a few variations that work.  (Spoiler:  I wouldn't use any of these; see below.) A)  Test for undef at time of use. module part1() { if (!is_undef(CrossSection) && CrossSection) { ... whatever ... } } B)  Define a function, and call it when you need the answer. function shouldCrossSection( ) = is_undef(CrossSection) ? false : CrossSection; module part1() { if (shouldCrossSection()) { ... whatever ... } } C)  Define a second name at the top level, or inside a block for use in that block. shouldCrossSection = is_undef(CrossSection) ? false : CrossSection; if (shouldCrossSection) { ... whatever ... } D)  Define a new variable with the same name, inside a block, for use in that block. module part1() { CrossSection = is_undef(CrossSection) ? false : CrossSection; if (CrossSection) { ... whatever ... } } Note that this is not *changing* the value of the variable; it is creating a new variable inside this block. But none of those is what I would do.  They all use a global variable, lexically scoped.  It's not quite correct to say that you're stuck with it across your entire model, but it's close.  Also, they don't work across "use <foo.scad>"; they only work across "include <foo.scad>", and for a lot of purposes "use" is better because it hides the details of one file from the other. I would use a $ variable, so that it's dynamically scoped.  I'd still use a function to test it.  The result would be sort of like function shouldCrossSection() = is_undef($CrossSection) ? false : $CrossSection; module part1() { if (shouldCrossSection()) { ... do whatever ... } } module part2() { if (shouldCrossSection()) { ... do whatever ... } } module part3() { if (shouldCrossSection()) { ... do whatever ... } } and then you could do $CrossSection = true; part1(); part2(); part3(); and all three parts would be cross-sectioned, or you could do part1($CrossSection=true); part2($CrossSection=false); part3(); and only part1 would be cross-sectioned.  Since false is the default, part3() doesn't get cross-sectioned.