BrownTiger

Ruby enumerating objects: List Of Rooms, areas or sq ft

Recommended Posts

Sometimes it is pretty cool to see total sq of a group of objects, total # of porches, or group together roof planes, or do something with a group.

 

Since not everyone is a software developer, have time to research Ruby... Here is a simple way to do this:

We want to use array of arrays [or to be exact hashmap of hashmaps] to store the data that will be displayed later.

I use a single global: $tree. The hashmap $tree["rooms"] will be storing rooms and whatever properties you feel are needed.

 

== To aggregate Rooms for example ==

1) First create a macro called labelRoom to be placed into room label [defaults->Floors and Rooms->Room Label] and lets name it labelRoom

 

referenced ? obj = referenced : obj = owner

if $tree.nil?

$tree = Hash.new { |hash, key| hash[key] = {} }

end

 

#id="r" + obj.to_s.gsub('#<NVPublisher:0x000','').gsub('>','') <-- X10

id="r" + obj.object_id.to_s

items = Hash.new()

items['room_name']=obj.name

items['floor_number']=obj.floor_number

items['internal_area']=obj.internal_area

$tree['rooms'][id]=items

""

 

2) Create enumeration macro

Macro: showSqft

result=""

$tree["rooms"].keys.each do |key|

result += "Room: " + $tree["rooms"][key]['room_name'] + "[" + $tree["rooms"][key]['floor_number'].to_s + "]" + " \t" + $tree["rooms"][key]["internal_area"].round(0).to_s + " sq ft\n"

end

result

3) Place this macro into a TextEdit

Done

================================================================================

Other times you may want to aggregate nameless objects like roof planes, here is how you can do this.

Macro: labelRoofPlane

referenced ? obj = referenced : obj = owner

if $tree.nil?

$tree = Hash.new { |hash, key| hash[key] = {} }

end

 

#id="p" + obj.to_s.gsub('#<NVPublisher:0x000','').gsub('>','') <--X10

id="p" + obj.object_id.to_s

items = Hash.new()

items['roof_plane']=id

items['pitch']=obj.automatic_label

items['area']=obj.surface_area

$tree['roofplanes'][id]=items

s =obj.automatic_label

s

 

Macro showRoofArea

result=""

sqft=0

 

$tree["roofplanes"].keys.each_with_index do |key,index|

s= index.to_s

result += "Plane: " + s +"\t" + $tree["roofplanes"][key]['pitch'] + " \t" + $tree["roofplanes"][key]["area"].round(0).to_s + " sq ft\n"

sqft +=$tree["roofplanes"][key]["area"].round(0)

end

result += "Total: " + sqft.to_s + "sq ft\n"

result

 

Aggregator.thumb.jpg.2dbe26e0e291aef457d9b3cb64f3921e.jpg

 

===

Bug fixed in a room name macro (Big Thanks to Alaskan_Son)

  • Like 1
  • Upvote 1

Share this post


Link to post
Share on other sites

Thanks BT , very interesting . appreciate you Posting this Tip.

 

Perhaps you should Post it and any further Tips in the Tips Forum , people may miss it here in the Symbols Forum.

Share this post


Link to post
Share on other sites

Thanks to the original poster for posting this.  I am interested in learning ruby but, I sure have a lot to learn.  As I was trying to use this ruby code in my plan, I could not get the info in the text edit box to populate for more than one roof plane.  It only shows info for roof plane zero.  I must be doing something wrong or overlooking something.

 

image.thumb.png.de82066ea6917ce5b365d00af8d40a96.png

 

image.thumb.png.f4c341a767e1dd32a3bfa9a55771d5e2.png

 

image.thumb.png.9804b927ec83a0d94fe8832bafc53206.png

 

 

 

Share this post


Link to post
Share on other sites

Sorry, did not see your post. The code was provided for X10. In x11 new property was offered... obj.object_id.

 

You need to change this line id="p" + obj.to_s.gsub('#<NVPublisher:0x000','').gsub('>','')

INTO: id ="p" + obj.object_id.to_s

 

See below 

 

Macro: labelRoofPlane

referenced ? obj = referenced : obj = owner

if $tree.nil?

$tree = Hash.new { |hash, key| hash[key] = {} }

end

 

id ="p" + obj.object_id.to_s

items = Hash.new()

items['roof_plane']=id

items['pitch']=obj.automatic_label

items['area']=obj.surface_area

$tree['roofplanes'][id]=items

s =obj.automatic_label

s

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

  • Member Statistics

    27611
    Total Members
    6254
    Most Online
    ChiefAKBuilder
    Newest Member
    ChiefAKBuilder
    Joined