Nabble has removed Mailing-list integration.
Posts created here DO NOT GET SENT TO THE MAILING LIST.
Mailing-list emails DO NOT GET POSTED TO THE FORUM.
So basically the Forum is now out of date, we are looking into migrating the history.

For now you should send emails, people will see them, discuss@lists.openscad.org.

Need some help with "if-else" statement.

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

Need some help with "if-else" statement.

entomophile
I have the following code working correctly:

//Size of larger tube?
tube_1 = 33.7; //[13.8:BT-5, 18.7:BT-20, 24.8:BT-50, 33.7:BT-55, 34.2:BT-56, 41.6:BT-60, 56.3:BT-70, 66.04:BT-80, 100:BT-101]

//Size of smaller tube?
tube_2 = 13.8; //[13.8:BT-5, 18.7:BT-20, 24.8:BT-50, 33.7:BT-55, 34.2:BT-56, 41.6:BT-60, 56.3:BT-70, 66.04:BT-80, 100:BT-101]

//How long do you want the taper to be?
taper_length = 25;

//Diameter of the hole through the center?  Use "0" for no hole.  Must be smaller than diameter of the small tube.
hole = 12.4;

wall_1 = .53;

wall_2 = .33;

difference(){

union(){
   
cylinder(h=taper_length, r1=tube_1/2, r2=tube_2/2, center=false, $fn=100);

translate([0,0,taper_length]) cylinder(h=12.7,r=tube_2/2-wall_2, center=false, $fn=100);

translate([0,0,-12.7]) cylinder(h=12.7,r=tube_1/2-wall_1, center=false, $fn=100);
}

translate([0,0,-12.7]) cylinder(h=taper_length+25.4, r=hole/2, center=false, $fn=100);    
}

I would like the "wall_1" and "wall_2" values to be dependent upon the selections for "tube_1" and "tube_2".  I have been trying to use an if/else statement but I haven't been able to get it to work.

I am trying to do something like "If tube_1=13.8, 18.7, or 24.8; then wall_1=0.33, else wall_1=0.53".

Any ideas?
Reply | Threaded
Open this post in threaded view
|

Re: Need some help with "if-else" statement.

nophead
wall_1 = tube_1 == 13.8 || tube_1 == 18.7 || tube_1 == 24.8 ? 0.33 : 0.53;


On 7 October 2015 at 17:09, entomophile <[hidden email]> wrote:
I have the following code working correctly:

//Size of larger tube?
tube_1 = 33.7; //[13.8:BT-5, 18.7:BT-20, 24.8:BT-50, 33.7:BT-55, 34.2:BT-56,
41.6:BT-60, 56.3:BT-70, 66.04:BT-80, 100:BT-101]

//Size of smaller tube?
tube_2 = 13.8; //[13.8:BT-5, 18.7:BT-20, 24.8:BT-50, 33.7:BT-55, 34.2:BT-56,
41.6:BT-60, 56.3:BT-70, 66.04:BT-80, 100:BT-101]

//How long do you want the taper to be?
taper_length = 25;

//Diameter of the hole through the center?  Use "0" for no hole.  Must be
smaller than diameter of the small tube.
hole = 12.4;

wall_1 = .53;

wall_2 = .33;

difference(){

union(){

cylinder(h=taper_length, r1=tube_1/2, r2=tube_2/2, center=false, $fn=100);

translate([0,0,taper_length]) cylinder(h=12.7,r=tube_2/2-wall_2,
center=false, $fn=100);

translate([0,0,-12.7]) cylinder(h=12.7,r=tube_1/2-wall_1, center=false,
$fn=100);
}

translate([0,0,-12.7]) cylinder(h=taper_length+25.4, r=hole/2, center=false,
$fn=100);
}

I would like the "wall_1" and "wall_2" values to be dependent upon the
selections for "tube_1" and "tube_2".  I have been trying to use an if/else
statement but I haven't been able to get it to work.

I am trying to do something like "If tube_1=13.8, 18.7, or 24.8; then
wall_1=0.33, else wall_1=0.53".

Any ideas?



--
View this message in context: http://forum.openscad.org/Need-some-help-with-if-else-statement-tp14080.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Need some help with "if-else" statement.

entomophile
That works!  Wow, so much going on in that one line of code.  Thanks so much for the help.
Reply | Threaded
Open this post in threaded view
|

Re: Need some help with "if-else" statement.

Shaporev, Timur
In reply to this post by nophead
wall_1 = tube_1 < 25 ? 0.33 : 0.53;
:-)
________________________________________
From: Discuss [[hidden email]] on behalf of nop head [[hidden email]]
Sent: 07 October 2015 19:26
To: OpenSCAD general discussion
Subject: Re: [OpenSCAD] Need some help with "if-else" statement.

wall_1 = tube_1 == 13.8 || tube_1 == 18.7 || tube_1 == 24.8 ? 0.33 : 0.53;


On 7 October 2015 at 17:09, entomophile <[hidden email]<mailto:[hidden email]>> wrote:
I have the following code working correctly:

//Size of larger tube?
tube_1 = 33.7; //[13.8:BT-5, 18.7:BT-20, 24.8:BT-50, 33.7:BT-55, 34.2:BT-56,
41.6:BT-60, 56.3:BT-70, 66.04:BT-80, 100:BT-101]

//Size of smaller tube?
tube_2 = 13.8; //[13.8:BT-5, 18.7:BT-20, 24.8:BT-50, 33.7:BT-55, 34.2:BT-56,
41.6:BT-60, 56.3:BT-70, 66.04:BT-80, 100:BT-101]

//How long do you want the taper to be?
taper_length = 25;

//Diameter of the hole through the center?  Use "0" for no hole.  Must be
smaller than diameter of the small tube.
hole = 12.4;

wall_1 = .53;

wall_2 = .33;

difference(){

union(){

cylinder(h=taper_length, r1=tube_1/2, r2=tube_2/2, center=false, $fn=100);

translate([0,0,taper_length]) cylinder(h=12.7,r=tube_2/2-wall_2,
center=false, $fn=100);

translate([0,0,-12.7]) cylinder(h=12.7,r=tube_1/2-wall_1, center=false,
$fn=100);
}

translate([0,0,-12.7]) cylinder(h=taper_length+25.4, r=hole/2, center=false,
$fn=100);
}

I would like the "wall_1" and "wall_2" values to be dependent upon the
selections for "tube_1" and "tube_2".  I have been trying to use an if/else
statement but I haven't been able to get it to work.

I am trying to do something like "If tube_1=13.8, 18.7, or 24.8; then
wall_1=0.33, else wall_1=0.53".

Any ideas?



--
View this message in context: http://forum.openscad.org/Need-some-help-with-if-else-statement-tp14080.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

_______________________________________________
OpenSCAD mailing list
[hidden email]<mailto:[hidden email]>
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Need some help with "if-else" statement.

entomophile
Another good solution, thank you.  I wasn't aware of the conditional operator.  Very useful.