Ruby Code Help


ACADuser
 Share

Recommended Posts

Started reading up on Ruby today in my spare time (not enough of that) but did get my first code to work.

I use closed polylines to do some crude load calcs. In this one I am attempting to get the Soil Pressure from the foundation, wall & roof.

This is just an approximation based on the tributary area of the roof (40 PSF TL). I use a 1' wide rectangle spanning to the midpoint between bearings to the eve in this case.

The code appears to work but I wanted to get some advice of the coding style I used. And any other comment relevant to the coding.

One issue I could not overcome was the use of puts which made the code chuck & wobble.

Any helpful comments are welcome.

 

I tried to use puts like this but it doesn't work:

_area = referenced.area
_roofTL = $roof_tl
_RL=(_area * _roofTL)
plf = (685+123+(_area * _roofTL)).round(1)
psf=(plf / 16 / 12).round(1)

puts "Roof Load "+ _area.round(1).to_s + "x" + $roof_tl.to_s + " TL="+ (_area.round(1)*$roof_tl).to_s  + "  PLF"
puts "CMU Wall 685 PLF"
puts "16x8 Foundation 133.4 PLF"
puts  plf.to_s + " PLF TL on Soil"
puts psf.to_s + " PSF Soil Load"

 

My working code:

_area = referenced.area # tributary area

_roofTL = $roof_tl # Global Roof Total Load = 40.0

_RL=(_area * _roofTL)

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 pounds

wall_wt=685.0 # 9'-4" CMU wall weight with 3 course stem wall (MOL)

 

plf = (wall_wt+ftr_wt+(_area * _roofTL)).round(1)

psf=(plf / (ftr_w / 12.0)).round(1)

 

str="Roof Load "+ _area.round(1).to_s + "x" + $roof_tl.to_s + " TL="\

+ (_area.round(1)*$roof_tl).to_s + " PLF" \

+ "\nCMU Wall #{wall_wt.round(0)} PLF\n16x8 Foundation 133.4 PLF\n" \

+ plf.to_s + " PLF TL on Soil\n" + psf.to_s + " PSF Soil Load"

 

CA Code1.JPG

Link to comment
Share on other sites

You can't use 'puts' in a CA macro as it writes a string to the console and there is no console to write to. CA transfers the output of a macro to their display internally.

 

Use 'p' instead. It returns 'inspects' instead of string.

 

Also macros only return the last known value so using multiple 'p' or puts will not give a multiple line output.

 

 

Your last string is the correct method of chaining strings for output  although Using expression substitution , #{} is a cleaner method.

You might consider using a polyline with label (avoids using reference) as a more reliable method. to stop it's output to the label -- just end with a nil

Link to comment
Share on other sites

So would this be the way you would phrase the last variable?

 

str="Roof Load #{_area.round(1).to_s} x #{$roof_tl.to_s} TL=#{ (_area.round(1)*$roof_tl).to_s}  PLF" \
        +  "\nCMU Wall #{wall_wt.round(0)} PLF \n16x8 Foundation 133.4 PLF \n#{plf.to_s} PLF TL on Soil \n#{ psf.to_s} PSF Soil Load"
 

Link to comment
Share on other sites

This brings up another issue,

For polyline labels, you only have one choice for label layer?

Can that be true?

 

There are so many different uses for polylines and they are on many different layers.

You should not be restricted to only one layer for labels.

Say it ain't so.

 

PS

OK when the pline layer is off  the label is off too, but that method does not free up multiple uses for pline labels.

.

 

Link to comment
Share on other sites

20 minutes ago, ACADuser said:

OK I figure it out.

Set Context to OWNER and do not use owner.area just use area.

 

 

You can use either

if you use owner.area, you do not need to set Context and can leave it at none. As always, the object must be selected or the macro must be in a label.( assuming reference is not used)

Link to comment
Share on other sites

There is no attribute for wall height in Chief as of now. You can check the available attributes for any object by selecting the object and using the macro 'ObjectProperties'. ( or load a custom list macro - easier.

Generally wall heights are determined by using the room attribute finished_floor_elevation and ceiling_elevation etc.

 

There is no default method to load or save Globals with the plan in Chief -- as of now.

There are several workarounds -- depending on your preference & effort. The easiest to just put your Globals in a Script to be automatically loaded on the start of Chief.

However, if you change a Global than you have to manually change the script. You can also load and save a text file.

 

You can also load and save Globals in a hash using Marshall - Which is beyond the scope of a few paragraphs here  -- several other options based on your level of desired effort.

Happy to do a "goto meeting" with you to explain/explore options if you want to explore further & think it's worth while? Otherwise just put them in a macro to be executed within a object or the MM or the OIP of a object.

 

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

  • Member Statistics

    30212
    Total Members
    9156
    Most Online
    Monikafb
    Newest Member
    Monikafb
    Joined
  • Similar Content

    • By buzzsaw204
      hi all,
      i have a Library of Ruby macro that was custom coded for me few years back.
      some the task/script is not working anymore cuz of the X12 upgrade.
      i would like have this Library upgraded and refresh the Code to the X12 version. and get it working again.
       
      the Library was very well and beautifully coded by another guru/ruby master.
      But unfortunately, iam unable reach the original programmer to redo this project.
       
      im looking for someone that could help and take over and upgrade this Library.
       
      Please contact me.