Hello everyone. Is there a way to get the sum of the numbers generated by the division command using split.index? For example, we have a 5-story building and if we use the split.index command, the floors start from zero and finally the 5th floor receives the number 4 and the sum is 10, that is, 0+1+2+3+4 = 10
Solved! Go to Solution.
I'm curious whether your goal is simply to compute the sum of split.index values,
or if you also want to pass that sum into other rules for further use.
If your goal is just to calculate the sum, you can use the formula "(split.total - 1) * split.total / 2"
If you'd like to pass the calculated value to other rules and use it there, you can write it like this:
attr unitHeight = 2 // Height of each split section
@StartRule
Lot -->
extrude(10) // Give height to the lot
split(y){ ~unitHeight : Section }* // Split along Y into equal parts
// Use 'with' to define sum_n as the sum of split.index values
Section
with ( sum_n := (split.total - 1) * split.total / 2 )
-->
case split.index == 0 :
Something_A(sum_n)
..
...
....
else :
Something_Else(sum_n)
There may be various ways to approach this, so please take this as a reference only.
Hi @maziaryousefi,
I believe split.total shape attribute is what you are looking for. Let's say you split your mass into three pieces, then split.index is 0,1,2 and split.total is 3.
See also split shape attribute in the CGA reference.
Cheers
Jonas
I'm curious whether your goal is simply to compute the sum of split.index values,
or if you also want to pass that sum into other rules for further use.
If your goal is just to calculate the sum, you can use the formula "(split.total - 1) * split.total / 2"
If you'd like to pass the calculated value to other rules and use it there, you can write it like this:
attr unitHeight = 2 // Height of each split section
@StartRule
Lot -->
extrude(10) // Give height to the lot
split(y){ ~unitHeight : Section }* // Split along Y into equal parts
// Use 'with' to define sum_n as the sum of split.index values
Section
with ( sum_n := (split.total - 1) * split.total / 2 )
-->
case split.index == 0 :
Something_A(sum_n)
..
...
....
else :
Something_Else(sum_n)
There may be various ways to approach this, so please take this as a reference only.
Thanks for your answer - I want to get the total electricity consumption of the floors and then display it in the report panel at the top of the building. I used the same method as you but it gives the wrong result. I think I need to find a way to associate the amount of electricity consumed by each floor with numerical indices split.index via the set command. If you have any ideas on this, I would be happy to hear it.