RUBY Questions


wjmdes
 Share

Recommended Posts

I have found several online sources for RUBY, but I am confused on a few issues and how Chief uses RUBY.  I am trying to streamline my code analysis and there are variables that are used throughout and I always forget to change somethings that are used over and over.

 

First question is how do you use the "inch" symbol: "  in a string?  I got (2) ' to do the trick (''), but is there a proper way?

 

I put together the following macro for a portion of my analysis:

 

$TO = 94 #Total occupants LSF

$CFL = 0.2 #Capacity Factor, Level, LSC Table 7.3.3.1

LSC = "37" #LSC Chapter for Occupancy

$ep = 2 #Exits Provided

 

"TOTAL OCCUPANTS =#{$TO}

(LSC: #{LSC}.2.3.2)

CAPACITY FACTOR = #{$CFL} (LSC TABLE 7.3.3.1)

#{$TO} PERSONS x #{$EW}'' = #{$TO*$CFL}''

(#{$ep}) 36'' EXITS PROVIDED = #{$ep*36} > #{$TO*$CFL}'', OK"

 

It works (so far):

 

TOTAL OCCUPANTS =94

(LSC: 37.2.3.2)

CAPACITY FACTOR = 0.2 (LSC TABLE 7.3.3.1)

94 PERSONS x 0.2'' = 18.8''

(2) 36'' EXITS PROVIDED = 72 > 18.8'', OK

 

The problem I am encountering is the way I format.  I would like to be able to use the variables throughout the several pages of text including the bold paragraph headings. 

 

First part:

771145793_CodeAnalysis.thumb.JPG.51f37e921a261134d8df4ea809b0831a.JPG

 

One good example is the Chapter of the LSC which is based on  the occupancy and I have 12 occurences of this hence, the variable "LSC" so I would like to declare that and just use it in the places needed.

For this I created a macro %code_lsc_chapter% which is simply: "#{LSC}" and this seemed to work.

 

My goal is to create a data macro I would edit for each job with comments for me to go through systematically with other macros to fill in the spot holder:

$TO = 94 #Total occupants LSF

$CFL = 0.2 #Capacity Factor, Level, LSC Table 7.3.3.1

LSC = "37" #LSC Chapter for Occupancy

$ep = 2 #Exits Provided

 

The problem I am having is if the variables are in a different macro, the subsequent macros can't find them.  I have seen mentioned on the forum that if I put them in a text box somewhere and hide it off to the side it fixes this issue.  This is where I feel stupid.  How do I write a variable to a text box or is that the wrong solution.

 

Basically I want to be able to use the data macro variables in other macros.

Link to comment
Share on other sites

9 minutes ago, wjmdes said:

First question is how do you use the "inch" symbol: "  in a string?

For this one, you just need to use the escape character (backslash) like this...

 

”24\””

 

Don’t have time to answer the second part right now.  

Link to comment
Share on other sites

1 hour ago, Joe_Carrick said:

Global variables are persistent and can be accessed in other macros.

  • $TO
  • $CFL
  • $ep

can all be used in other macros within the same session of Chief.  In your case:

  $TO -> "94 #Total occupants LSF"

 

This is the output I get when I create a separate macro without the variables in it.  Basically I just copied the original macro with a different name and removed the variables and put them in a different macro

 

"TOTAL OCCUPANTS =#{$TL}

(LSC: #{LSC}.2.3.2)

CAPACITY FACTOR = #{$CFL} (LSC TABLE 7.3.3.1)

#{$TL} PERSONS x #{$EW} = #{$TL*$CFL} inches

(#{$ep}) 36 inch EXITS PROVIDED = #{$ep*36} > #{$TL*$CFL} inches, OK"

 

Basically I just copied the original macro with a different name and removed the variables:

 

$TL = 94 #Total occupants LSF

$CFL = 0.2 #Capacity Factor, Level, LSC Table 7.3.3.1

$LSC = "37" #LSC Chapter for Occupancy

$ep = 3 #Exits Provided

Link to comment
Share on other sites

Bill,

 

I don't understand your last post.  

  1. Your Global Variables are all string values.  
  2. To perform math you need to convert to floating point
  3. If you are just looking up values from a table it should work.
  4. However, it appears that you are actually assigning new values to the Globals.

What are you expecting?

Link to comment
Share on other sites

 

2 minutes ago, Joe_Carrick said:

Bill,

 

I don't understand your last post.  

  1. Your Global Variables are all string values.  
  2. To perform math you need to convert to floating point
  3. If you are just looking up values from a table it should work.
  4. However, it appears that you are actually assigning new values to the Globals.

What are you expecting?

 

I was hoping on each project to define items, whether numbers or text. that would be used to populate my code analysis.  If the variables are in the same macro it allows me to do the math, etc.  I think I figured out a workaround....

Link to comment
Share on other sites

One of the most fundamental pieces of the puzzle is this:

 

You can USE your global variables in as many macros as you wish but you need to make sure you only DEFINE the global variable in a single location. Also, in order to use the global variable, the macro that defines the variable needs to be executed somewhere in your view (it can either return a blank value or it can be dragged off to the side).

Link to comment
Share on other sites

5 minutes ago, wjmdes said:

 

 

I was hoping on each project to define items, whether numbers or text. that would be used to populate my code analysis.  If the variables are in the same macro it allows me to do the math, etc.  I think I figured out a workaround....

Consider using your macros in the Labels of Rooms, CAD Boxes, etc.  That way you can use the dimensional data (Ruby attributes) of those objects to calculate and display results.  If those results are stored as global variables you can  have a macro in a text box that retrieves the data and displays it as needed.

Link to comment
Share on other sites

Untitled 2.layout

 

This is what I was trying to do and how I got it to work.  I am a little confused Joe as you said these were all strings.  The math in the macro worked so how do I declare them numbers?

If there is a better solution, please let me know.  I am trying to learn more.  This exercise will save me a bunch of time and minimize editing in the future.

Link to comment
Share on other sites

5 minutes ago, wjmdes said:

The math in the macro worked

Probably because of the code block syntax you used.  In Ruby it's common practice to use the method .to_f to convert a string to a floating point value or the method .to_i to convert to an integer value.  You can also use the method .to_s to convert a numerical value to a string. 

 

I'm not personally a great fan of code blocks - mostly because I don't fully understand all the nuances of their use.

I also think not using code blocks makes the script easier to read and understand.

Link to comment
Share on other sites

On 5/3/2021 at 1:18 PM, wjmdes said:

Untitled 2.layout 300.85 kB · 3 downloads

 

This is what I was trying to do and how I got it to work.  I am a little confused Joe as you said these were all strings.  The math in the macro worked so how do I declare them numbers?

If there is a better solution, please let me know.  I am trying to learn more.  This exercise will save me a bunch of time and minimize editing in the future.

 

I didn't study all your methodology or syntax in great deal, but just doing a quick once over, I see that you appear to have a typo in the last line of your code_data macro...

 

pic.png

Link to comment
Share on other sites

On 5/3/2021 at 5:44 PM, Joe_Carrick said:

I'm not personally a great fan of code blocks

Can you please clarify what you mean by this?  Just trying to learn.

 

 

9 minutes ago, Alaskan_Son said:

I didn't study all your methodology or syntax in great deal, but just doing a quick once over, I see that you appear to have a typo in the last line of your code_data macro...

Thanks for looking at it.  As I expanded and realized how useful this could be, I changed some variables so they were a bit more obvious what they were.

Link to comment
Share on other sites

2 minutes ago, wjmdes said:
On 5/3/2021 at 1:44 PM, Joe_Carrick said:

I'm not personally a great fan of code blocks

Can you please clarify what you mean by this?  Just trying to learn.

 

I'm not 100% sure, but I think he's referring to the Interpolation you're using  ----> "#{code}" 

 

Interpolation isn't really a code block.  It's just a little trick to insert code into a string. 

 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share