Pieces of a whole

classic Classic list List threaded Threaded
22 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Pieces of a whole

dbvanhorn
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 [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Pieces of a whole

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

On Mon, 22 Mar 2021 at 15:38, david vanhorn <[hidden email]> 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 [hidden email]

_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Pieces of a whole

dbvanhorn
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 <[hidden email]> wrote:
if(is_undef(CrossSection) ? false : CrossSection) ...;

On Mon, 22 Mar 2021 at 15:38, david vanhorn <[hidden email]> 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 [hidden email]
_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]


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

_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Pieces of a whole

dbvanhorn
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 <[hidden email]> 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 <[hidden email]> wrote:
if(is_undef(CrossSection) ? false : CrossSection) ...;

On Mon, 22 Mar 2021 at 15:38, david vanhorn <[hidden email]> 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 [hidden email]
_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]


--
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 [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Pieces of a whole

dbvanhorn
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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> wrote:
if(is_undef(CrossSection) ? false : CrossSection) ...;

On Mon, 22 Mar 2021 at 15:38, david vanhorn <[hidden email]> 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 [hidden email]
_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]


--
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 [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Pieces of a whole

acwest
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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> wrote:
if(is_undef(CrossSection) ? false : CrossSection) ...;

On Mon, 22 Mar 2021 at 15:38, david vanhorn <[hidden email]> 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 [hidden email]
_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]


--
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 [hidden email]

_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Pieces of a whole

nophead
In reply to this post by dbvanhorn
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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> wrote:
if(is_undef(CrossSection) ? false : CrossSection) ...;

On Mon, 22 Mar 2021 at 15:38, david vanhorn <[hidden email]> 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 [hidden email]
_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]


--
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 [hidden email]

_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Pieces of a whole

dbvanhorn
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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> wrote:
if(is_undef(CrossSection) ? false : CrossSection) ...;

On Mon, 22 Mar 2021 at 15:38, david vanhorn <[hidden email]> 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 [hidden email]
_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]


--
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 [hidden email]
_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]


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

_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Pieces of a whole

nophead
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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> wrote:
if(is_undef(CrossSection) ? false : CrossSection) ...;

On Mon, 22 Mar 2021 at 15:38, david vanhorn <[hidden email]> 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 [hidden email]
_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]


--
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 [hidden email]
_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]


--
K1FZY (WA4TPW) SK  9/29/37-4/13/15
_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]

_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Pieces of a whole

JordanBrown
In reply to this post by dbvanhorn
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.

_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Pieces of a whole

JordanBrown
In reply to this post by dbvanhorn
On 3/22/2021 10:26 AM, david vanhorn wrote:
I knew you couldn't change variables, but I didn't think that assigning one which was undefined was "changing" it.

It isn't, or at least not exactly, but that's not the key problem.
if (... some test ...) {
    x = 3;
} else {
    x = 5;
}
echo(x);

gives you an unknown-variable warning, because the two values of x only last for those one-line blocks.  When you're done with the "if", you're back to the state before the "if", which is that x is undefined.

General rule:  blocks are black holes.  It is *not possible* to get information out of them.  There is nothing that you can do inside a block that is visible to the program outside the block.  (A block can return a geometric object, but the program can't then *look* at that object.)

You *can* say

x = is_undef(x) ? 3 : x;

but it doesn't really work.  It's fine if x is undefined, but if x *is* defined at that block level, it's an error because it tries to change the value.  (Even if it's trying to change it to the same value.)




  


_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Pieces of a whole

dbvanhorn
In reply to this post by acwest
I've been writing code for a long time. I understand globals.  If they weren't occasionally useful, they wouldn't exist.

On Mon, Mar 22, 2021 at 11:21 AM A. Craig West <[hidden email]> wrote:
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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> wrote:
if(is_undef(CrossSection) ? false : CrossSection) ...;

On Mon, 22 Mar 2021 at 15:38, david vanhorn <[hidden email]> 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 [hidden email]
_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]


--
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 [hidden email]
_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]


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

_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Pieces of a whole

jon_bondy
I agree...

On 3/22/2021 2:16 PM, david vanhorn wrote:
> I've been writing code for a long time. I understand globals.  If they
> weren't occasionally useful, they wouldn't exist.
>
_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Pieces of a whole

dbvanhorn
In reply to this post by nophead
Ok using the function approach works for me, all my sub parts are now generating completely if invoked separately, and in cutaway when invoked from the cross section file.

However... :)

From the cross section file, a preview is taking a while to generate, and when it's done there are issues.
Rotating or zooming is VERY slow, and it looks like the cross sectioning is only happening on some angles (??)
Also my torus part is only partially generating. Possibly it is clipping and the rest are not?

Parsing design (AST generation)...

Compiling design (CSG Tree generation)...

Compiling design (CSG Products generation)...

Geometries in cache: 91

Geometry cache size in bytes: 10194352

CGAL Polyhedrons in cache: 22

CGAL cache size in bytes: 96578656

Compiling design (CSG Products normalization)...

Normalized tree has 2085 elements!

Compile and preview finished.

Total rendering time: 0:00:00.321

See the files Xsection..

If I render the file, it all looks exactly like it should.
Rotations and zooms are fast and smooth, and everything works as it should, and it looks good from all angles.
I don't get any warnings in either case.

Geometries in cache: 91

Geometry cache size in bytes: 10194352

CGAL Polyhedrons in cache: 22

CGAL cache size in bytes: 96578656

Total rendering time: 0:03:27.306

Top level object is a 3D object:

Simple: yes

Vertices: 7825

Halfedges: 37910

Edges: 18955

Halffacets: 22280

Facets: 11140

Volumes: 6

Rendering finished.





On Mon, Mar 22, 2021 at 11:25 AM nop head <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> wrote:
if(is_undef(CrossSection) ? false : CrossSection) ...;

On Mon, 22 Mar 2021 at 15:38, david vanhorn <[hidden email]> 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 [hidden email]
_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]


--
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 [hidden email]
_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]


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

_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]

Xsection4.png (30K) Download Attachment
Xsection ok 2.png (24K) Download Attachment
Xsection ok.png (18K) Download Attachment
Xsection3.png (30K) Download Attachment
Render1.png (20K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Pieces of a whole

JordanBrown
On 3/22/2021 11:44 AM, david vanhorn wrote:
From the cross section file, a preview is taking a while to generate, and when it's done there are issues.
Rotating or zooming is VERY slow, and it looks like the cross sectioning is only happening on some angles (??)
Also my torus part is only partially generating. Possibly it is clipping and the rest are not?

I can't really speak to the performance issue.

Preview gets two common artifacts that are angle-sensitive.

Some of the operations have a "convexity" parameter that hints to the previewer how complex the object is.  It defaults to 1, which is a terrible default.  There's almost no penalty to setting it to 10.  The symptom is that some pieces of the model end up transparent.

The previewer doesn't like it if the camera is inside any part of the model - including the big cubes that you might be using for clipping, whether using intersection or difference.  Keep the camera outside those cubes.  I've never really characterized the misbehavior, but it can lead to parts of the model appearing and disappearing.


_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Pieces of a whole

dbvanhorn
Ok, I am using a big cube for clipping.  Kinda unavoidable.
I have long wished for clipping planes as implemented in PovRay.   No dimensioning necessary, everything on one side of the plane is gone, the rest stays.

On Mon, Mar 22, 2021 at 1:02 PM Jordan Brown <[hidden email]> wrote:
On 3/22/2021 11:44 AM, david vanhorn wrote:
From the cross section file, a preview is taking a while to generate, and when it's done there are issues.
Rotating or zooming is VERY slow, and it looks like the cross sectioning is only happening on some angles (??)
Also my torus part is only partially generating. Possibly it is clipping and the rest are not?

I can't really speak to the performance issue.

Preview gets two common artifacts that are angle-sensitive.

Some of the operations have a "convexity" parameter that hints to the previewer how complex the object is.  It defaults to 1, which is a terrible default.  There's almost no penalty to setting it to 10.  The symptom is that some pieces of the model end up transparent.

The previewer doesn't like it if the camera is inside any part of the model - including the big cubes that you might be using for clipping, whether using intersection or difference.  Keep the camera outside those cubes.  I've never really characterized the misbehavior, but it can lead to parts of the model appearing and disappearing.



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

_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Pieces of a whole

JordanBrown
On 3/22/2021 12:08 PM, david vanhorn wrote:
Ok, I am using a big cube for clipping.  Kinda unavoidable.
I have long wished for clipping planes as implemented in PovRay.   No dimensioning necessary, everything on one side of the plane is gone, the rest stays.

Yes.  I have no idea whether the underlying tools (CGAL, OpenCSG) are friendly to that notion.  It'd kind of have to be a primitive, since there are no infinite-size constructs in the language today.


_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Pieces of a whole

dbvanhorn
Understood.  

On Mon, Mar 22, 2021, 4:32 PM Jordan Brown <[hidden email]> wrote:
On 3/22/2021 12:08 PM, david vanhorn wrote:
Ok, I am using a big cube for clipping.  Kinda unavoidable.
I have long wished for clipping planes as implemented in PovRay.   No dimensioning necessary, everything on one side of the plane is gone, the rest stays.

Yes.  I have no idea whether the underlying tools (CGAL, OpenCSG) are friendly to that notion.  It'd kind of have to be a primitive, since there are no infinite-size constructs in the language today.


_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Pieces of a whole

nophead
OpenCSG preview draws differences by using graphics operations, so it draws all the negative objects. If they are too big to fit within the clipping region faces outside the region are not drawn. That breaks the CGS operation.

It is best not to subtract massive objects if a smaller one will do the job or you can use render() to calculate the resulting geometry and just draw that as a polyhedron. Then you can zoom in as far as you want

On Mon, 22 Mar 2021 at 23:00, david vanhorn <[hidden email]> wrote:
Understood.  

On Mon, Mar 22, 2021, 4:32 PM Jordan Brown <[hidden email]> wrote:
On 3/22/2021 12:08 PM, david vanhorn wrote:
Ok, I am using a big cube for clipping.  Kinda unavoidable.
I have long wished for clipping planes as implemented in PovRay.   No dimensioning necessary, everything on one side of the plane is gone, the rest stays.

Yes.  I have no idea whether the underlying tools (CGAL, OpenCSG) are friendly to that notion.  It'd kind of have to be a primitive, since there are no infinite-size constructs in the language today.

_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]

_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Pieces of a whole

LenStruttmann
In reply to this post by JordanBrown
I am new to OpenSCAD and I am finding that I, also, use the Big Cube method for clipping.  

Is there a way to get the maximum dimensions (preferably in all six directions from center) of an assembly?  This would help in quickly creating a reasonably sized cube for clipping.

Thanks!

On Mon, Mar 22, 2021 at 5:32 PM Jordan Brown <[hidden email]> wrote:
On 3/22/2021 12:08 PM, david vanhorn wrote:
Ok, I am using a big cube for clipping.  Kinda unavoidable.
I have long wished for clipping planes as implemented in PovRay.   No dimensioning necessary, everything on one side of the plane is gone, the rest stays.

Yes.  I have no idea whether the underlying tools (CGAL, OpenCSG) are friendly to that notion.  It'd kind of have to be a primitive, since there are no infinite-size constructs in the language today.

_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]

_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]
12