Variables storage

2215
4
04-03-2012 06:34 AM
TalAisenberg
New Contributor III
Hey,

Is there a way to store a value at some point in the code so I can use it later - for example:
I want to determine a building's height based on the plot size and its footprint (in order to get my FAr right). So I need to:

1. Measure the plot - geometry.area and save it
2. create the building footprint with ShapeL (or offset / ShapeU....)
3. now calculate based on a target FAR the height of the building (FAR = plot area / (footprint * no. of stories))
4. extrude the building to the required height

Its just that once I've done the shapeU operation I cannot go back to read the plot area as geometry.area(bottom) will now give me the building footprint.

I tried with assigning the value to a new attr on the Lot rule (just before I divide them) but this doesn't seem to work.

Cheers
T


p.s. working with really tedious urban planners - you know how they can sometimes be 😐
0 Kudos
4 Replies
AndréCardoso
New Contributor III
I'm not sure what you have tried to do already ... but have you tried to use the "set(attr, attrValue)" function?

Something like this:
@Hidden
attr originalArea = 0

Lot -->
   print("Original Area", geometry.area)
   set(originalArea, geometry.area)
   BuildShape

BuildShape -->
    shapeL(3, 4){shape: ShapeRule | remainder: NIL}

ShapeRule -->
   alignScopeToAxes(y)
   print("Original Area Again", originalArea)
   print("Current Shape area", geometry.area)
   extrude(world.y, originalArea/8) # calculate height in function of oriignal footprint area
   Shape.


Does it work?
0 Kudos
AndréCardoso
New Contributor III
Another possibility is just to pass the original area down to the next rules, as Rule parameters...
Lot --> 
Rule2(geometry.area)

Rule2(area) -->
Rule3(area)

...
0 Kudos
TalAisenberg
New Contributor III
Brilliant, Set does the trick.

The problem with the second option is that I only need to use the variable in routines 4 or 5 levels down so bit cumbersome to pass it on and on.

Thanks again,
T
0 Kudos
AndréCardoso
New Contributor III
Exactly! For me, one the great things added in these recent versions of CE was the capability to use "set()" with attributes defined by us. Things get much cleaner...

🙂
0 Kudos