/

/

04-flat-summarizer

/

/

04-flat-summarizer

Day

04

pyRevit

Challenge

Day

04

pyRevit

Challenge

|

|

|

|

|

|

|

|

|

|

|

|

|

|

|

21-Day pyRevit Challenge

Mon

Tue

Wed

Thr

Fri

Sat

Sun

Tool Of The Day:

"Flat Summarizer"

Watch Bonus Training:
- Follow pyRevit FastTrack Setup
- Watch P.R.O.C.E.S.S. Masterclass

As you know, we can't make a simple sum of all apartment rooms. Instead, we have to follow specific rules and guidelines for correct results...

Plus, I'm ready to bet that every office has their own specific workflow in Revit on how to do that...

So, let's create a custom Flat Summarizer.

Today We're Practicing:

>>>

Getting Elements with Collector

>>>

Getting Elements with Collector

>>>

Read/Write Parameters

>>>

Read/Write Parameters

>>>

Read Properties

>>>

Read Properties

>>>

Transactions

>>>

Transactions

>>>

Convert Revit API Units✨

>>>

Convert Revit API Units✨

Let's Create

"Flat Summarizer"

Using 7-Step PROCESS

.

.

.

.

.

.

.

PLAN

Ready To Sum It Up?

If you tried to summarize rooms in Revit then you know the struggle…

  • Revit calculates room sums wrong

  • You can't tag correct sums without workarounds

  • You often need to sort with multiple criteria (Building, Apartment #, Usage Type…)

So, The Goal for Today's Tool:

Create apartment summarizer. It should sort all rooms in the project by building and apartments and then calculate correct sums that can be displayed with a tag.

As you know we can have Living spaces, Balcony/Terrace, Loggias, Basement storage… And all of them are treated differently based on your local regulations… And as a cherry on the top, we'll also calculate without any rounding errors like Revit does it...

Today's Tool Demo:

This takes less than 50 lines of code!

.

.

.

.

.

.

.

PLAN

Ready To Sum It Up?

If you tried to summarize rooms in Revit then you know the struggle…

  • Revit calculates room sums wrong

  • You can't tag correct sums without workarounds

  • You often need to sort with multiple criteria (Building, Apartment #, Usage Type…)

So, The Goal for Today's Tool:

Create apartment summarizer. It should sort all rooms in the project by building and apartments and then calculate correct sums that can be displayed with a tag.

As you know we can have Living spaces, Balcony/Terrace, Loggias, Basement storage… And all of them are treated differently based on your local regulations… And as a cherry on the top, we'll also calculate without any rounding errors like Revit does it...

Today's Tool Demo:

This takes less than 50 lines of code!

.

.

.

.

.

.

.

RESEARCH

Coding CheatSheet

Here's everything you might need for today's challenge.

Coding Blocks

Get Rooms

Sort Rooms with 2 parameters

Get / Write to Parameter

Get / Read Parameters

Convert Units To Metric

Get Rooms

Get / Read Parameters

Sort Rooms with 2 parameters

Convert Units To Metric

Get / Write to Parameter

Revit API Docs
  1. Transaction() Constructor

  2. UnitTypeId Class

  3. UnitUtils Class

  4. FilteredElementCollector Class

  5. Room Class

  6. Element.LookupParameter Method

  7. Parameter.Set Method

Notes

🔸Revit API uses Feet internally!
This means that if you want to read values, you'll get them in feet. And if you want to change Revit values, make sure you provide it in feet.

So many people wasted hours on debugging because they forgot to convert units… Myself included.

🔸When you write to parameters:
When you use Parameter.Set - make sure you provide correct StorageType. Otherwise nothing will happen, you won't even get an error which can be confusing.

🔸If you use Revit 2021 or lower:
There were minor changes to methods for converting units before Revit 2022… Double check documentation.

AI Prompt

You can ask AI to help you with the research
but it's NOT 100% perfect solution. Do not rely too much on AI.

AI Research Prompt

AI Prompt

You can ask AI to help you with the research
but it's NOT 100% perfect solution. Do not rely too much on AI.

AI Research Prompt

.

.

.

.

.

.

.

RESEARCH

Coding CheatSheet

Here's everything you might need for today's challenge.

Coding Blocks

Get Rooms

Get / Read Parameters

Sort Rooms with 2 parameters

Convert Units To Metric

Get / Write to Parameter

Revit API Docs
  1. Transaction() Constructor

  2. UnitTypeId Class

  3. UnitUtils Class

  4. FilteredElementCollector Class

  5. Room Class

  6. Element.LookupParameter Method

  7. Parameter.Set Method

Notes

🔸Revit API uses Feet internally!
This means that if you want to read values, you'll get them in feet. And if you want to change Revit values, make sure you provide it in feet.

So many people wasted hours on debugging because they forgot to convert units… Myself included.

🔸When you write to parameters:
When you use Parameter.Set - make sure you provide correct StorageType. Otherwise nothing will happen, you won't even get an error which can be confusing.

🔸If you use Revit 2021 or lower:
There were minor changes to methods for converting units before Revit 2022… Double check documentation.

AI Prompt

You can ask AI to help you with the research
but it's NOT 100% perfect solution. Do not rely too much on AI.

AI Research Prompt

.

.

.

.

.

.

.

.

.

.

.

.

.

.

OUTLINE

Step-by-Step Plan

Break down logic of the tool idea into smaller chunks so it's easier to brainstorm, find hidden steps and code.

OUTLINE

Step-by-Step Plan

Break down logic of the tool idea into smaller chunks so it's easier to brainstorm, find hidden steps and code.

1

Get All
Rooms

card-background

4

Write Room
Results

card-background

2

Sort Rooms
By Apartment

card-background

5

Optionally:

Count Rooms

card-background

3

Calculate
Usage SUMs

card-background

*

Ensure To
Convert Units!

card-background

1

Get All
Rooms

card-background

3

Calculate
Usage SUMs

card-background

4

Write Room
Results

card-background

2

Sort Rooms
By Apartment

card-background

*

Ensure To
Convert Units!

card-background

5

Optionally:
Count Rooms

card-background

.

.

.

.

.

.

.

OUTLINE

Step-by-Step Plan

Break down logic of the tool idea into smaller chunks so it's easier to brainstorm, find hidden steps and code.

1

Get All
Rooms

card-background

2

Sort Rooms
By Apartment

card-background

3

Calculate
Usage SUMs

card-background

*

Ensure To
Convert Units!

card-background

4

Write Room
Results

card-background

5

Optionally:

Count Rooms

card-background

NB!

TRY BUILDING
THIS TOOL YOURSELF
DON'T RUSH TO SOLUTION

Unless… You're a Beginner


According to GENERATION EFFECT

The Harder You Work, The Deeper It'll be Wired in Your Brain

NB!

TRY BUILDING
THIS TOOL YOURSELF
DON'T RUSH TO SOLUTION

Unless… You're a Beginner


According to GENERATION EFFECT

The Harder You Work, The Deeper It'll be Wired in Your Brain

NB!

TRY BUILDING
THIS TOOL YOURSELF
DON'T RUSH TO SOLUTION

Unless… You're a Beginner


According to GENERATION EFFECT

The Harder You Work, The Deeper
It'll be Wired in Your Brain

.

.

.

.

.

.

.

.

.

.

.

.

.

.

CODE

Code Quick-n-Dirty.

The Goal is to create a proof of concept. Don't try to make it perfect. Skip steps if necessary. Keep it ugly. Keep it slow. JUST. MAKE. IT. WORK…

CODE

Code Quick-n-Dirty.

The Goal is to create a proof of concept. Don't try to make it perfect. Skip steps if necessary. Keep it ugly. Keep it slow. JUST. MAKE. IT. WORK…

Proof Of Concept

So for this Proof Of Concept we're going to skip a few steps.

It will be more than enough if we just:

  • Get all Rooms

  • Sort Rooms by Apartments

  • And Calculate Usage Sums

And then when this part works, we'll go to the next step where we'll write it to correct parameters, and maybe calculate amount of bedrooms in apartment.

Proof of concept works!

SCRIPT: PROOF OF CONCEPT

SCRIPT: PROOF OF CONCEPT

.

.

.

.

.

.

.

CODE

Code Quick-n-Dirty

The Goal is to create a proof of concept. Don't try to make it perfect. Skip steps if necessary. Keep it ugly. Keep it slow. JUST. MAKE. IT. WORK…

Proof Of Concept

So for this Proof Of Concept we're going to skip a few steps.

It will be more than enough if we just:

  • Get all Rooms

  • Sort Rooms by Apartments

  • And Calculate Usage Sums

And then when this part works, we'll go to the next step where we'll write it to correct parameters, and maybe calculate amount of bedrooms in apartment.

Proof of concept works!

SCRIPT: PROOF OF CONCEPT

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

EDIT

Refactor Everything

Once proof-of-concept works - we can focus on all steps to make everything more structured, optimized and easier to read.

EDIT

Refactor Everything

Once proof-of-concept works - we can focus on all steps to make everything more structured, optimized and easier to read.

EDIT

Refactor Everything

Once proof-of-concept works - we can focus on all steps to make everything more structured, optimized and easier to read.

REFACTORED CODE

REFACTORED CODE

REFACTORED CODE

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

STRESS-TEST

Time To Break It!

Don't rush sharing your tools.

Try breaking it before your team does it… You don't want to hear how your tools fails at the cost of your reputation.

STRESS-TEST

Time To Break It!

Don't rush sharing your tools.

Try breaking it before your team does it… You don't want to hear how your tools fails at the cost of your reputation.

STRESS-TEST

Time To Break It!

Don't rush sharing your tools.

Try breaking it before your team does it… You don't want to hear how your tools fails at the cost of your reputation.

Ensure Room Parameters

Whenever you try to get Project/Shared parameter it's worth checking if you managed to get them. Becaus it's very likely that not all project will have them…

Be careful trying to read/write values to shared parameters without checking.

Caption

Solution:

Solution:

Solution:

Ensure Flat Rooms

Whenever you try to get anything - you have to double check if you got it. Because often times - there's no point execution the rest of the code…

So let's verify if we have flat rooms in our project.

And keep in mind that we can have room in the project, but none of them would have flat parameters… So make sure you check dict_flats and not all_rooms.

Caption

Solution:

Solution:

Solution:

Ensure Occupancy value

ChatGPT gave a good hint that we shouldn't try to apply .lower() after reading a built-in parameter.

Yes - it will always be in all projects.
But - It can be None.

Because by default parameters have special None state. It doesn't have any value, but it's also not empty… It just doesn't exist (None).

And this can be problematic when we expect to get a string…

So let's rewrite this section and skip apartment rooms if they don't have an occupancy.

Caption

Solution:

Solution:

Solution:

Ensure Output Parameters Exist

Whenever you try to get Project/Shared parameter it's worth checking if you managed to get them. Becaus it's very likely that not all project will have them…

Be careful trying to read/write values to shared parameters without checking.

Caption

Solution:

Solution:

Solution:

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

SHIP

Submit Your Code.

Congratulations! Another tool is complete.

Now let's reflect on what we've learnt and submit your code to keep track of your progress.

SHIP

Submit Your Code.

Congratulations! Another tool is complete.

Now let's reflect on what we've learnt and submit your code to keep track of your progress.

SHIP

Submit Your Code.

Congratulations! Another tool is complete.

Now let's reflect on what we've learnt and submit your code to keep track of your progress.

Time To Celebrate

Share Your Win On LinkedIn
With #pyRevitChallenge

I'll Embed You Here!

© 2023-2026 EF Learn Revit API

© 2023-2026 EF Learn Revit API

© 2023-2026 EF Learn Revit API