Fast-Track pyRevit Systemโ„ข

Lesson 8

Framework for creating new pyRevit tools

Written Summary

The 7-Step Framework for Building pyRevit Tools ๐Ÿ› ๏ธ

We're finally diving into pyRevit development โ€” and I know you want to jump straight into the code editor. But let's take one step back first.

In this lesson, I'll introduce you to the framework I use for every single tool I build. It takes any rough idea โ€” even a weak one โ€” and turns it into a working, robust, stress-tested tool. Follow these 7 steps and you'll get better results, in less time, with way more predictable outcomes.

Forget perfect code on the first try

Forget the perfect tool. Follow a repeatable process: what keeps you stuck vs what actually works

Here's the truth: perfect code on the first try doesn't happen. Tutorials show you clean code working immediately, but real development isn't like that.

You'll write messy code. You'll get stuck. Bugs will pile up. That's normal โ€” even I go through all of that. It's just part of the process that tutorials usually skip (and I get it, I make tutorials too โ€” that's just how tutorials work).

What keeps people stuck:

  • Trying to write a perfect script from scratch

  • Watching tutorials but building zero tools

  • Copy-pasting AI code without understanding it โ€” that's a recipe for disaster when you share tools with your team

What actually works is building tools before you feel ready. We'll always start with an ugly proof of concept first and polish it later. That's how you ship robust, tested tools.

The 7 steps at a glance

Every tool starts with one idea, and then goes through the same seven steps:

  1. Plan โ€” define what you're doing and why

  2. Research โ€” steal like an artist, find all the help you can get

  3. Outline โ€” pseudo-code in plain English, no code yet

  4. Code โ€” quick and dirty, just prove it works

  5. Edit โ€” polish, add features, optimize

  6. Stress Test โ€” break it in every way possible before anyone else can

  7. Ship โ€” put it in production and let people use it

The 7-step PROCESS framework: Plan, Research, Outline, Code, Edit, Stress-Test, Ship

It works for any tool you can imagine. Now let's walk through all seven steps on a real tool we're going to build: NameSwapper. It renames views in bulk instead of you clicking them one by one โ€” select views, define renaming rules, rename, and report what changed. One button click.

NameSwapper tool: select views, define rules, rename views, report changes - with live UI mockup

Step 1: Plan based on a real problem

Step 1 Plan: a real problem and a WHY - is it repetitive, does it happen on every project, is it worth automating

Before opening the code editor, define the real problem and understand why you're even automating it.

For example: every project is full of views, and renaming them by hand is really tedious. Standards change, new batches get created, requirements shift. So the plan: one tool to rename views in bulk, with a friendly UI so anyone on the team can use it.

Then decide if it's worth automating. Ask yourself:

  • Is it repetitive? โœ… Yes

  • Does it happen on every project? โœ… Yes

  • Can anyone on the team use it? โœ… Yes

  • Is it worth automating? โœ… Absolutely

๐Ÿ’ก Tip: Make sure you're solving a real problem. Sometimes we build tools, look at them, and go "hmm, not exactly what I expected." Planning first saves you from that.

Step 2: Research โ€” steal like an artist

Step 2 Research: steal like an artist - grab pieces from Google, YouTube, Docs, Forums, AI

Look everywhere: Google, YouTube, the docs, forums โ€” and nowadays, mostly AI doing the research for you. Often there's already an existing tool that does pretty much the same thing, or at least one of your steps is solved somewhere.

For NameSwapper, research might turn up:

  • A video showing how to select views with pyRevit

  • A blog post revealing there are forbidden symbols for view names

  • Examples of how to handle a name that already exists

  • Documentation showing you can rename views with the .Name property โ€” no parameters or methods needed

  • How to create simple UI forms

Don't spend too much time here. Just gather something useful โ€” you can feed it to AI later to help it help you, and at minimum you'll understand the problem better yourself.

Step 3: Outline in plain English

No code yet. If you can't put your tool into plain English, you're not ready to write Python either.

This is a classic programming concept: take one big problem and break it into as many small problems as possible. For NameSwapper:

  1. Select views in the project

  2. Define renaming rules (hardcoded or with a UI form)

  3. Rename each view one by one

  4. Report what changed

Write it on paper if you want. These steps will literally become the structure of your code โ€” you can even type them as comments in your editor right away.

Step 3 Outline: pseudo-code in plain English - 4 numbered steps before any Python

Step 4: Code โ€” quick and dirty ๐Ÿš€

The goal here is a proof of concept, fast. Don't spend days trying to make the first steps perfect. Skip steps, hardcode values โ€” if it's ugly, that's totally fine. Build it one step at a time.

Selecting views? Research already showed us it's two lines with pyRevit forms. Rules? Just hardcode something to test with. Here's what the ugly-but-working version looks like:

# -*- coding: utf-8 -*-
from pyrevit import forms
from Autodesk.Revit.DB import Transaction

doc = __revit__.ActiveUIDocument.Document

# 1. Select views
views = forms.select_views()

# 2. Define renaming rules (hardcoded for now - cut corners!)
find    = 'Level'
replace = 'LVL'

# 3. Rename views one by one
t = Transaction(doc, 'NameSwapper - Rename Views')
t.Start()

for view in views:
    old_name = view.Name
    new_name = old_name.replace(find, replace)
    view.Name = new_name

    # 4. Report what changed
    print('{} -> {}'.format(old_name, new_name))

t.Commit()

Notice the Transaction. Since we're making changes to a Revit project, we have to wrap them in one โ€” by default your code can't change anything. That's the beauty of the Revit API: it has safeguards so beginners can't mess up a project without even knowing it.

โš ๏ธ Important: Focus on proof of concept first. Early in my journey, I tried building something like DiRoots ProSheets before it existed โ€” and spent nearly two weeks on a perfect UI form before realizing I had no idea how to actually make the PDFs. I had to abandon it. If I'd built the proof of concept first, I'd have known on day one and moved on to other tools.

Once this runs and gives you results โ€” even if it breaks half the time โ€” you know what's going on, and you're ready for the next phase.

Step 5: Edit โ€” now you can polish

Once the proof of concept works, now we polish. Swap hardcoded values for a real UI form, add features, optimize. We can afford to spend time on the UI now because we know everything else is achievable.

The progression usually looks like this:

  • Proof of concept (ugly, hardcoded)

  • Add the UI layer

  • Improve the output โ€” tables instead of raw prints, maybe linkify elements so you can select and open views quickly

  • Slowly arrive at the final tool

Step by step, without jumping too fast.

๐Ÿ–ผ๏ธ [IMAGE: Side-by-side progression of NameSwapper โ€” hardcoded POC output, then with a UI form, then the polished version with a table report]

Step 6: Stress test โ€” break it before your users do

Many people stop after editing and send the tool to the team. And that's where you get the weird looks: someone clicks your button, gets a scary error, and thinks "did I break something?" You'll look at it and go "oh, just a typo" โ€” but they don't know that. They'll be scared to ever click your button again.

So we break it ourselves first. And honestly, it's mostly the same things that break on nearly every tool:

  • The user selects nothing and breaks your form

  • The user closes the UI too early without selecting correctly

  • The new name already exists in the project

  • The name contains forbidden symbols

Once you know the issues, solving them is way easier than finding them:

# Exit early with a friendly message instead of a scary error
views = forms.select_views()
if not views:
    forms.alert('No views selected. Please select views and try again.',
                exitscript=True)

# Wrap risky operations so one bad view does not kill the whole run
try:
    view.Name = new_name
except Exception as e:
    print('Could not rename {}: {}'.format(old_name, e))

And clean user inputs so forbidden symbols never make it into a view name in the first place.

Go through your code step by step and logically dissect it. If there's a UI โ€” how can someone break it? If there's a step that gets elements โ€” what if it gets none? What if there are no such elements in the project at all? What if they picked the wrong ones?

๐Ÿ’ก Tip: At first this feels painful, but it gets very repetitive fast โ€” the same handful of issues come up again and again. Spend enough time here; this is what makes your tools production-ready. (And in pyRevit School we go through the whole debugging protocol with the most common places where code breaks.)

๐Ÿ–ผ๏ธ [IMAGE: Friendly forms.alert dialog saying "No views selected" โ€” compared next to a raw Revit API error traceback]

Step 7: Ship it

The most exciting step. Put your tool in production, add it to the toolbar, and let other people use it. The stress test passed, you can't break it anymore โ€” and if some user still finds a way, you fix it and move on. Totally fine.

This is where you bring value at scale, even while you sleep. A regular Revit user spends X hours and gets Y results โ€” and there's a limit to how far that goes. With code, there's no limit: you write it once, and it produces results over and over. For you, your team, maybe multiple offices, maybe everyone you share it with. That's the beauty of programming.

These are the 7 steps to create any pyRevit tool from scratch. Repeat them until they're a habit โ€” it'll happen naturally anyway, but if you're conscious about it, it'll happen much sooner.

What's next

Enough theory โ€” in the next lesson we're going to build it together. Time to create your first pyRevit tools, step by step. See you there!