Reusing conditional statements?
Reusing conditional statements?
(OP)
This is structural in nature but could apply to any subject:
I have set up a set of if statements that will output a rebar diameter based on rebar size. That's no problem.
bar_diameter := |0.375 in if bar_size = 3
|0.500 in if bar_size = 4 (etc.)
However, I have several different bar sizes within a structure. I am trying to define different diameters depending on the location (i.e. bar_diameter_compression, bar_diameter_tension) without having to redefine my conditional statement above to suit each location (i.e. bar_size_compression, bar_size_tension) since a bar size has a specific diameter regardless of location.
Any way of using this one definition above to suit every location and keep it local to whichever bar I am working with? Is there a better way of defining this (something like a case statement)? Sorry about being so wordy.
I have set up a set of if statements that will output a rebar diameter based on rebar size. That's no problem.
bar_diameter := |0.375 in if bar_size = 3
|0.500 in if bar_size = 4 (etc.)
However, I have several different bar sizes within a structure. I am trying to define different diameters depending on the location (i.e. bar_diameter_compression, bar_diameter_tension) without having to redefine my conditional statement above to suit each location (i.e. bar_size_compression, bar_size_tension) since a bar size has a specific diameter regardless of location.
Any way of using this one definition above to suit every location and keep it local to whichever bar I am working with? Is there a better way of defining this (something like a case statement)? Sorry about being so wordy.





RE: Reusing conditional statements?
I wish you'd been more prolix! As I understand it you want to define the conditional statement once, and then have local values for the returned diameter.
I am not conversant with the structure shown, but why not set up a matrix of bar diameters, with say the rows being the size and the columns being the flag that defines the local condition (say column 0 for tension, 1 for compression etc etc)
.
Then define a function to refer to the matrix elements.
I'm not sure if this will work by picking up the local value of flag, you may have to include that in the function call, so you would have to
1)define your matrix
2) write your function
bar_diameter(f,bs):=matrix[bs,f]
or just return the matrix result directly, which is not as clear
3)Then call it with
newbardia:=bar_diameter(flag,barsize)
Is that clear?
Cheers
Greg Locock
RE: Reusing conditional statements?
bar_dia := {0.00 0.00 0.375 0.500 0.625 0.750 0.875 1.00 etc.}
a.s := {0.00 0.00 0.11 0.20 0.31 0.44 0.60 0.79, etc.}
Note the first to 0's.. this means that the position is the rebar size.
so a.s[7 gives me the area of steel for a #7 bar and bar_dia[7 gives me the diameter.
Imagineer
RE: Reusing conditional statements?
Cheers
Greg Locock
RE: Reusing conditional statements?
I agree with the idea of building a matrix. I made 3 matrices (bar, diam, area) since they are different units, which can be used for the entire sheet. I made a pull-down menu of all bar sizes and by selecting a size, it stored the index of the selected bar. When I select bar_size_tens := 6 (from the menu), the program returns the index, bar_size_tens = 4 (bar #'s start at 3).
Finally, bar_diameter_tens := diam[bar_size_tens. Then I recreate the menu for different locations (i.e. bar_size_comp := same pull-down menu).
RE: Reusing conditional statements?
Huh? There is only one diameter for a given bar_size. Did I misunderstand your post?
Imagineer
RE: Reusing conditional statements?
So he wants a 2d array
Cheers
Greg Locock