Ruby - Sqrt?


KristjanM
 Share

Recommended Posts

I commonly do a quick calculation for pad footing sizes for estimating purposes. If an engineer is involved, he/she will do the calculations. I've created a text box which gives me the area, loads and footing size in square feet. I would like to get the square root of the footing area and multiply by 12 to give me the footing edge size in inches (assuming the pad is square). I've tried various things such as sqrt() or math.sqrt() both in the text box and in the ruby console but can't generate a correct result. Can you do math functions in a text box? Do I have to call an actual macro. What is the right syntax?

Area & Label.jpg

Area & Label Text.jpg

Link to comment
Share on other sites

I just tried the following in the Ruby Console:

  • y = 450.00 ; x = Math.sqrt(y).round(4)      ---> 21.2132

It works fine.  However, the data in the parentheses has to be numerical.  Otherwise you'll get an error.

 

Also note that Ruby is case sensitive.  So as Eric said, Math works, math doesn't.

Link to comment
Share on other sites

Tried in the Ruby console (should return 2) -

 

> Math.sqft(4)

=> Ruby NoMethodError: undefined method `sqft' for Math:Module

Stack Trace:

from eval:10:in `eval'

from eval:10:in `block (2 levels) in <main>'

from eval:4:in `loop'

from eval:4:in `block in <main>'

Link to comment
Share on other sites

Okay, thanks to all for your help. 1st issue - don't type sqft when you need sqrt. 2nd issue - sqrt doesn't work in a text box but does work in the ruby console. So...need to make a macro. Thanks again.

Link to comment
Share on other sites

Eric is correct that it works in a text box - but you have to put it there as a macro evaluation.  ie %...........%.

You can even use a RTB and get all sorts of formatting.  The advantage however of using a custom macro is that it can get data from the owner or referenced object and use that to return results.

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