Obtain quantity sum of instances of type Revit API C#

Obtain quantity sum of instances of type Revit API C#

rita.aguiar
Advocate Advocate
1,081 Views
4 Replies
Message 1 of 5

Obtain quantity sum of instances of type Revit API C#

rita.aguiar
Advocate
Advocate

Is it possible to obtain the quantity sum of all instances of a type through the Revit API?

Any help would be appretiated.

 

In similarity to what this schedule is obtaining:

Sum.png

 

 

0 Likes
Accepted solutions (1)
1,082 Views
4 Replies
Replies (4)
Message 2 of 5

BenoitE&A
Collaborator
Collaborator

I guess so : 

- you can filter your model the same way you do it in your Schedule (FilteredElementCollector, ofCategory, Where, etc...)

- you can evaluate the value of your given parameter for every Instance in this collector

- you can sum these.

 


Benoit FAVRE
CEO of etudes & automates
www.etudesetautomates.com/
Message 3 of 5

rita.aguiar
Advocate
Advocate

@BenoitE&A 

Ah, what a pity. Is that the best way? I was hoping I could find a property that would return the sum so I didn't have to do it myself.

Thanks for the reply.

Message 4 of 5

BenoitE&A
Collaborator
Collaborator

We gave it a thought with my associate and did not come with anything simpler. But frankly, it's not top-notch... really the same as creating a schedule...


Benoit FAVRE
CEO of etudes & automates
www.etudesetautomates.com/
0 Likes
Message 5 of 5

john_dalessandro
Contributor
Contributor
Accepted solution

Because LINQ lazy loads, the following should only run through each element once and be pretty quick.

 

return new FilteredElementCollector(doc)
    .OfCategory(/* category */)
    .Sum(e => e.get_Parameter(/* parameter */).AsDouble());