ACADuser Posted April 12, 2020 Share Posted April 12, 2020 What I want to do is test a global variable to see if I already assigned a valid value to it. If not assign a value now. Any value < 35 or nil is invalid for my requirements if $roof_tl < 35.0 $roof_tl=40.0 end This is the error Evaluation Error: Ruby NoMethodError: undefined method `<' for nil:NilClass Link to comment Share on other sites More sharing options...
Joe_Carrick Posted April 13, 2020 Share Posted April 13, 2020 if $roof_ti.nil? $roof_ti=40.0 elsif $roof_tl < 35.0 $roof_tl=40.0 end 1 Link to comment Share on other sites More sharing options...
ACADuser Posted April 13, 2020 Author Share Posted April 13, 2020 Thanks for that Joe. I started playing around again after not using these macros for some time. There is another error I can not understand. # total_roof_Load_CMU_wall_Label # apply to a closed polyline label. # ================================= # Alan Butler 10/06/2018 # Calculate the roof + wall + foundation weight for a # onestory 10' CMU wall + 2' stem wall # Foundation 16"x8" 150# concrete # ================================= _area = owner.area if $roof_ti.nil? $roof_ti=40.0 # Global Roof Total Load = 40.0 asphalt roofing elsif $roof_tl < 35.0 $roof_tl=40.0 end _roofTL = $roof_tl _RL=(_area * _roofTL) cmu8psf=55.0 # normal average weight 8" block w/ verticals grouted @ 48"oc ftr_w= 16.0 #footer width in inches ftr_h= 8.0 #footer heith in inches ftr_wt= (ftr_w*ftr_h/144.0*150) #footer weight in PLF w/ 150# / ft3 CC wall_ht= 10.0 # wall height wall_wt= ((wall_ht + 2.0) * cmu8psf) # 10'-0" CMU wall weight with 3 course stem wall = 12' total height plf = (wall_wt+ftr_wt+(_area * _roofTL)).round(1) # Wall + Footer + Roof psf=(plf / (ftr_w / 12.0)).round(1) # soil PSF str="Roof Load #{_area.round(1).to_s} x #{$roof_tl.to_s} TL=#{ (_area.round(1)*$roof_tl).to_s} PLF\n" \ + "CMU Wall #{wall_wt.round(0)} PLF \n"\ + "16x8 Foundation #{ftr_wt.round(1).to_s} PLF \n"\ + "#{plf.to_s} PLF TL on Soil \n"\ + "#{psf.to_s} PSF Soil Load" I don't remember this error before. Evaluation Error: Ruby ArgumentError: cannot add a Measurement of area to a unitless value Stack Trace: from (eval):28:in `+' from (eval):28:in `block (3 levels) in <main>' from (eval):1:in `instance_eval' from (eval):1:in `block (2 levels) in <main>' from eval:9:in `eval' from eval:9:in `block (2 levels) in <main>' from eval:3:in `loop' from eval:3:in `block in <main>' Link to comment Share on other sites More sharing options...
Chopsaw Posted April 13, 2020 Share Posted April 13, 2020 Likely your _area = owner.area needs to be converted to a float. _area = owner.area.to_f Yup that should do it.... It would be nice if chief could include the line number in the error code..... Oh and number the lines. Link to comment Share on other sites More sharing options...
ACADuser Posted April 13, 2020 Author Share Posted April 13, 2020 Wow, you mean we can not multiply a floating-point value by an integer? I'm sure this worked last time I used it in X11. Yes, it looks very difficult to troubleshoot ruby in Chief. How do you find out a variable value during the run of a routine? I don't see a way to test a variable to see if it is a string, integer or float. Link to comment Share on other sites More sharing options...
ACADuser Posted April 13, 2020 Author Share Posted April 13, 2020 How about this one? _area = owner.area if _area.nil? "No Area" else _area=_area.to_f plf = (_area * $roof_t).round(1).to_s end Link to comment Share on other sites More sharing options...
Joe_Carrick Posted April 13, 2020 Share Posted April 13, 2020 The error in post #3 is in line 28. from (eval):28:in '+' wall_wt= ((wall_ht + 2.0) * cmu8psf) # 10'-0" CMU wall weight with 3 course stem wall = 12' total height You have tried to add a floating point value to a measurement. wall_ht is a measurement in X12 2.0 is a floating point value This is not allowed in Chief so you either need to change 2.0 to a measurement or wall_ht to a floating point. Adding or subtracting measurements and non-measurements is not allowed. IMO Chief should have made this work by automatically converting the non-measurement value to a measurement of the same units. 1 Link to comment Share on other sites More sharing options...
ACADuser Posted April 13, 2020 Author Share Posted April 13, 2020 Thank you Joe! I got this to work too: _area = owner.area if $roof_tl.nil? $roof_tl=40.0 # Global Roof Total Load = 40.0 asphalt roofing elsif $roof_tl < 35.0 $roof_tl=40.0 end _RL=(_area.to_f * $roof_tl) if _area.nil? "No Area" else _area=_area.to_f plf = "AREA LOAD "+(_area * $roof_tl).round(1).to_s + "#" end BTW is there a simple way to add code tags to this forum post? Link to comment Share on other sites More sharing options...
Joe_Carrick Posted April 13, 2020 Share Posted April 13, 2020 Another way to trap errors is to use the following: begin if $roof_ti < 35.0 # This line could generate an error if $roof_ti has not been initiated $roof_ti = 40.0 end rescue $roof_ti = 40.0 end In this case if the error occurs in the line #2 it's trapped and line #6 is processed. This is standard Ruby error handling. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now