Fast-Track pyRevit Systemβ„’

/

/

/

12-ai-supercharge

Lesson 12

SuperCharge with AI

Written Summary

SuperCharge Your Tool with AI πŸ€–

By now you've got a solid NameSwapper tool that you can share with your team. But we can make it even better by supercharging it with AI.

In this lesson, we'll hand our tool to an AI agent and turn it into Swapper+ β€” an enhanced version with a custom WPF UI form for selecting views, setting renaming rules, and (most importantly) a live preview of every rename before you commit. That last part is the killer feature: you get to decide if the result is good before anything touches your model.

Pick your agent

There's a lot we could do with AI here, but let's keep the setup honest and simple.

  • I normally prefer Claude Code for all my agent workflows.

  • But to make this simpler and faster, we'll use Cursor's native agent β€” no setup at all, so we can all do it together right away.

  • For the model, I'm going with Claude 4.8 β€” that's a really good one β€” or maybe GPT 5.5. Whatever you prefer.

Don't overthink the choice. The process is what matters.

Step 1: Throw in a (slightly crazy) prompt

Let's go a little bit crazy with the first prompt:

Can you duplicate the NameSwapper button and create an enhanced version
where we add a custom WPF UI form with view selection, live preview
and naming rules? Call it Swapper

Send it in. This is a big ask β€” there are hundreds of lines of code just to create the UI form β€” so the agent is going to think for a while, working in a loop: create code, verify, fix, repeat.

⚠️ Important: Without any reference files, AI tends to write WPF code with vanilla settings. It works, but it's messy β€” and maintaining it wouldn't be nice. Keep that in mind when you let an agent build UI from scratch.

forms.WPFWindow: a real custom window from a .xaml file driven by Python - layout, class, live window

πŸ–ΌοΈ [IMAGE: Cursor agent panel with the Swapper+ prompt sent and the agent "thinking", new tool folder appearing in the extension file tree]

Step 2: Reload pyRevit while the agent thinks

These agents can take quite some time, so let's not just sit here. I can already see a new folder in our .extension folder, which means we can reload pyRevit now β€” even if the agent keeps changing the code, that's totally fine.

  1. Go to Revit and reload pyRevit.

  2. Wait for the new Swapper+ button to show up in your tab.

  3. Let the agent finish writing the code.

πŸ’‘ Tip: You only need to reload pyRevit to make a new button appear. Once the button exists, the code updates automatically every time you click it β€” no reload needed (unless you're working with libraries).

Step 3: Test the first version

The agent finished, so let's click the button and see what we get.

A form shows up! And here's the cool part: the agent went through our existing extension, found a working example, and used it as a base. I honestly expected it to come up with some random stuff β€” but no, it grabbed our form. If you go agentic with your own extension, most of your tools will get built this way: your existing code becomes the reference.

πŸ–ΌοΈ [IMAGE: First version of the Swapper+ WPF form β€” view list with checkboxes, search box, and basic renaming fields]

Now let's poke at it: Select None, search the views, try to find the "L" floor plans... and, okay, it's not perfect. L1 shows up, L2 doesn't exist in the list, the filtering is clunky. Not ideal.

And that's fine. First drafts from AI rarely are.

Step 4: Just ramble your feedback

So I don't like it β€” which means I go back to the agent and just kind of ramble about what's wrong:

I'm looking at the form you made and there are a few issues.
1. Selection: I want to be able to filter by view type β€” floor plans,
   areas, ceiling plans, drawing sheets and so on.
2. The selection and the preview should be separate. First I select my
   views, then I want to see the Current Name and New Name only for the
   selected views β€” maybe in different columns. That helps me navigate
   and check the results much better

πŸ’‘ Tip: You can often just ramble to these agents β€” they're pretty good at parsing it. Honestly, it beats carefully typing: you're faster, and you naturally throw in more context and extra details. Sure, it's a bit dirty, and you can always clean it up if things go sideways. But overall it works great.

While the agent works, here's the bigger point: you can push this really far. You can even spin up multiple agents working on multiple tools at once. But when you code with AI, it's really good if you can judge the code and the output. AI is great, but agents are either slow and thorough, or fast and a bit dumber β€” missing context, doing things the "kind of right" way but not the best way. Your understanding is what keeps it on track.

Step 5: The final Swapper+ in action

The agent made its changes. Let's open the tool again β€” and now it's working. Let's run through a real rename:

  1. Click Select None β€” the preview goes empty.

  2. Filter by Floor Plans and grab the L views: L1, L2, L3, L4, L5.

  3. In Find, type L. In Replace, type Level 0.

  4. Add a Suffix β€” something like draft.

  5. Watch the live preview update with the new names for only the selected views.

  6. Hit Rename. Perfect. Perfect!

πŸ–ΌοΈ [IMAGE: Final Swapper+ form β€” view type filter dropdown, selected L1–L5 floor plans, and the live preview showing Current Name vs New Name columns]

Under the hood, the renaming logic is the same one you built by hand earlier in this training:

from Autodesk.Revit.DB import Transaction
from pyrevit import revit

doc = revit.doc

def apply_rules(name, find, replace, prefix, suffix):
    return prefix + name.replace(find, replace) + suffix

t = Transaction(doc, 'Swapper+: Rename Views')
t.Start()
for view in selected_views:
    view.Name = apply_rules(view.Name, find, replace, prefix, suffix)
t.Commit()

The AI just wrapped it in a much nicer experience. We could even turn the output into another menu with more functionality β€” but hold that thought.

Judge the output β€” and know when to stop

This is why pyRevit is so much fun right now: we have agents, we have AI, we always have somewhere to get answers. But two honest warnings from this session:

⚠️ Important: Don't blindly follow the AI. It can go astray, and getting back on track from there can be really hard. There were a few suggestions in this build I didn't like and pushed back on. Normally you'd also set up a proper backup system (version control) so you can always roll back β€” but that's a topic for another time.

And second: AI gives you so much code power that you need to know when to stop. Sometimes you have to tell yourself: "Erik, don't do it. It's enough." The tool works. Ship it.

The full journey, start to finish

Look at what you just went through β€” all the stages of real tool development:

  • Plan β€” we talked it through and gathered research (okay, we took a shortcut, but still).

  • Proof of concept β€” maybe 5 minutes and 15 lines of code, and we already had a working tool.

  • Feature by feature β€” one, two, three, four, five... slowly building it up.

  • AI supercharge β€” at the end, we threw it at an agent: "do that, and that, and that."

Ship versions: v0.1 proof of concept to v1.0 final tool, each one a little better

And now you have an amazing tool that you can start using right away β€” and a process you can reuse for every tool you build from here. Try the same approach for creating modules, and keep experimenting with AI to see how far you can push it.

What's next πŸš€

Congratulations β€” you did a great job, and you've got a genuinely useful tool to show for it. There's just one more lesson left, where I'll talk about your next steps: what to focus on and how to keep getting better with pyRevit and the Revit API. See you in the next one!