This content guides users through the process of creating custom Revit add-ins using Py Revit, demystifying the development process and encouraging hands-on learning by building a practical "rename views" tool.
Mind Map
Click to expand
Click to explore the full interactive mind map • Zoom, pan, and navigate
hi everybody many of you think that it's
still very hard to create custom Revit
addings and I Want to Break Down The
Stereotype I want to take you step by
step for the process of creating new
tools for Revit but most importantly I
want you to feel what it's like to
create custom Revit addings once you
will create your first button you'll
want to create more you might even have
multiple ideas during this video for
your new tools that's how we all start
and the best way of learning is actually
by doing so let's get you into this
developers flow and create your first
custom par button in just a few minutes
but before we begin I actually expect
that you already have your own custom
parit extension created either with my
EF pit starter kit or you made it on
your own it only takes 2 minutes to
create your custom parit extension and
you can watch this video where I will
show you how to do that along with the
tour of my EFI RIT starter kit which is
absolutely free cuz there are a lot of
resources and code samples and I want
you to get the most out of it and now
let's create your first parid button I'm
going to create my button here in the
dev panel it's really good practice to
have a special panel where you create
new tools which can be unfinished and
once they finished you can move them
anywhere else by just moving the folder
so don't always stress where you're
going to create it to create it I'm
going to hold out and click on one of
these kind of place holder buttons and
it's going to open the folder where it's
located I can go one folder outside some
in my Dev panel and you can see in here
I have Dev button one two and three and
same is here going to go outside you
also see there a bunch of panels and I
also have here about resources
placeholder panel and death
panel so I'm going to go back to the
death panel and I'm just going to
duplicate one of the
buttons let's call it our first button
and most importantly make sure you spell
push button correctly if you cannot see
your button appear in pyit when we're
going to reload it it probably means
that you misspell this one push button
right here or maybe you haven't put a
script and an icon inside of there now
first of all let's place here an icon
and we also going to put some kind of
template inside of the script file so we
can actually continue creating our
button to place here an icon we can
actually go to resources and right here
we're going to go to icons8.com in here
we can get the free
resources in the search icons I'm going
to write here something like rename
because spoiler alert during this video
I'm going to show you how to rename your
views with py RIT and we're also going
to create little interface and so on but
you will see this in a
moment now in here I'm going to select
just a random icon I can click on the
download when you will be downloading
the icon make sure it's smaller than 96
by 96 pixels but you can always take it
smaller just to be safe now click on
download when it's ready just drag it
into the folder of your newly created
button now we can get rid of the
previous icon and rename this one to the
icon you could also create here a second
icon and call it icon the dark to have
different icons for the light and dark
theme but I don't want to do that I'll
be fine with just one icon now now we
have the icon let's open up the script
and change something there as well now
since I duplicated my existing button I
already have here some kind of template
but if you haven't done this we can go
to my EF pyit starter kit then here in
the templates have different templates
I'm going to click on py RIT minimum
template and here this is a very
simplified version we have some
description the name of the button a few
most important Imports a few variables
and just blocks for your main and
functions just going to copy that and
paste it here in my Buton Buton first of
all let's change the title in here I'm
going to call it rename
views then this is the description that
your user is going to see when they
hover over the button I'm just going to
quickly modify this and you can write
here anything you want but this is how I
prefer to do this first of all I like to
know the version and the date then in
here I'm going to write the description
of this button then depending on the
tool I like to describe how to use it
for example for this one I could write
something like click on the button then
select views Define renaming rules and
lastly rename views but it always
depends on how much information you want
to give to the users then for the update
it's good to track what kind of changes
you make but in this case I'm just going
to set the date and today is the release
of this tool then in here you can also
add some features that you are planning
to add later but I'm not going to be
planning anything for this tool all
right then in here we have our common
import our Autodesk import our P RIT
import and sometimes we need a list from
net Library this is how you get it and
here are our variables and here we're
going to write our code let's remove
function and now let's go to Revit then
we're going to go to P Revit tab I'm
going to click on this button right here
reload then on this menu say yes and
once it's reloaded when you're going to
go back to your toolbar you're going to
see a new button appear if you've done
everything correctly if you haven't done
anything correctly usually it's because
of the folder structure just make sure
that you put the right suffixes like
that push button that tab that panel all
of that also in the right order now
here's my button when I'm going to click
on it it just going to give me some kind
of print statement which is a template
has been developed by Eric frit which
comes from here on the bottom right we
don't need it let's remove it and now we
are ready to start coding but before
you're going to open your code editor I
want you to grab a piece of paper and a
pen we're going to do a little bit
brainstorming together to decide what
kind of tool are we creating as you
already understood from the name we're
going to rename our views by using fine
and replace logic this will help me to
introduce you to various RAV API concept
and also show you how to take a big tool
idea and break it down into smaller
manageable steps this is necessary as it
helps you to think more like a
programmer and you might discover some
hidden steps in between that you need to
address to avoid errors that's what we
also going to do and also a huge remark
here it doesn't need to be beautiful or
very detailed it just have to make sense
to you and also maybe it's just me but I
tend to rewrite the steps over and over
until they start making more sense to me
as it helps me to think about about the
problems and find a solution to them so
now let's think how should we rename our
view in Revit there are a few steps that
we need to do first of all we need to
grab a few views and there are two ways
we're going to do that first of all
we're going to try to get selected views
in the project browser in ravit UI and
if there is nothing selected then we're
going to select our views with the p
form and I'm going to show you how to
use it don't worry then we need to
define a few renaming rules such as what
do we want to find what we want to
replace it with the prefix the sufix and
all of that and then we will create a
new view name and we're going to rename
all of the views and also by looking at
this diagram you might realize that
there's actually extra step in between
because when we going to rename our
views we want to make sure that it's a
unique view name cuz otherwise we're
going to get an error saying that the
view name is not unique and it's not
going to rename it and we also might see
the red wall of text if you're not going
to use try and accept
statements all right and this is our
diagram this is what we're going to code
and you can use it as the comments in
your code or however you like it just
going to keep the paper in front of me
and follow along all right and now we're
going to go to the coding part let's
open our code editor and the first step
we're going to do is Select some views
let me zoom in as well so you can see it
better now as I mentioned in the diagram
we need first of all we're going to try
to get selected views and then we're
going to try to use the pirated form to
get the selected views the same as
getting our selected elements for that
we will need to make sure that we have
our UI do Define right here and can WR
here selected element IDs equals UI doc
selection and then there is a method
called get element
IDs now we want to take all of these
element IDs and convert it to selected
elements let's make it a list
comprehension I'm going to write dog get
element we're going to provide this
element IDs then in here we're going to
write for element ID in selected element
IDs so we're going to iterate for this
list I'm we're going to get the actual
element from the element ID now we don't
care really about all the selected
elements what we care about is selected
views so in here we're going to create
another Leist comprehension and there
we're going to write I want to get all
elements or element and selected
elements and in list comprehension we
can also make here an if statement and
in here I'm going to write if is subass
now we need to write type of the element
and we're going to provide
view this method right here will just
check if the type of the element is part
of the view or any of its children
classes cuz as you know in The
Inheritance hierarchy we have our view
and then there a lot of classes based on
it like view plan view section and all
of those classes so this will make sure
that we check if we have any views
selected and now let's add here a
comment that we're getting a views which
are selected in the project browser
however if you don't have anything
selected in the project browser we want
to get our views differently so this way
we're going to write if none
selected we're going to prompt select
views from parit forms and there is
something like select views I'm not sure
if that's how it's written but you will
see in a moment so we're going to just
write if not selected views then I'm
going to write selected views
equals and then in the import somewhere
right here you can see from pit we import
import
forms we're going to write here forms
and I'm going to write select views I
don't think I need to provide here any
arguments optionally I can provide my
title button name weave multiple all of
that but I can see that multiple is set
to true so I'm just going to leave it oh
and if you want to see the dock strings
can hold control and click on Q then
you're going to see this menu but to do
that you need to make sure that you set
your interpreter settings and it knows
where P rabit library is located in my
case right here I provided my RIT API
stops and right here I provided my pit
Masters pit lip folder this way P charm
knows about these functions and it can
read about them all right and before
we're going to go any further we need to
ensure that we have some views selected
again we're going to write if not
selected views and this time I'm going
to use forms alert I'm going to write
now views selected please try
again I'm going to write here exit
script equals to true this will make
sure that we stop execution of the code
we're not going to see anything further
for example let's write here print
done and if this is triggered we're
never going to see this print statement
done now let's open ravit and see if it
works I'm going to click on this button
and you will see I get a select menu I'm
like okay let's check everything and
click on select and it says no view
selected please try again probably means
that I messed up something let's come
back in here and right away I can see
right here because I use the variable
select views but in here accidentally I
wrote selected elements let's change
that and we're going to come back to
ravit now I'm going to click on it again
since I don't have anything selected I'm
supposed to get this menu and I do I'm
going to select all the
views right here the print statement
done means that I manag to select My
Views and the script continues but if
I'm going to click on here I don't
select anything and close it you're
going to get an alert no views selected
please try again but most importantly
it's going to stop execution of the code
and therefore we're not going to create
any errors we're not going to see any
wrong statements and so on and lastly we
can also select some views this way
right here click on rename views and
we're not supposed to see any form we're
just supposed to see the done because we
selected it on the first try right here
so this one worked and this one didn't
work didn't work and we continue with
the code CU we already have our selected
views all right selecting views is easy
let's go to the Second Step where we're
going to Define renaming rules at first
you can hardcode this values so we're
going to Define our fine replace sufix
prefix and we're going to create a
working script by using this values and
only then you can think about the UI
form because first of all you need to
make sure that it works before you start
thinking about how to make it pretty I
highly recommend you to create this MVP
which stands for minimum viable product
and it's just to prove your idea first
and then we can focus on optimizing and
make it look nicer and all of that
because you see in the past I've spent a
lot of hours making a nice forms for
something that apparently I couldn't do
at the time yet so make your MVP first
and once it working they you can focus
on all the forms and make it beautiful
all right now in my case I'm going to
look here for something like floor plan
and I'm going to replace it maybe with
level or anything else we're going to
change it later
anyway now the next step we need a
transaction because we are about to make
changes transactions in Revit API are
necessary to make any changes in your
Revit projects and that's great news for
the beginners because it just means that
you cannot mess up anything accidentally
in your projects while you explore ravit
API so you can feel safe and do whatever
you want with ravit API until you use
transactions cuz once you start using
them then you have to be really careful
what you do to define a transaction we
need to use the class
transaction I need to provide here a
document and the name of the change this
name is going to be shown in the undo
menu let's let's go to rename views and
sometimes it also might be a good idea
to put here some kind of prefix like e
if or maybe Pi so you know that it's
your Custom Tool
now we also need to Define here a
variable let's set T to equal
transaction and then we need to start
and we need to commit our
transactions let's also add here a few
icons and in here we're going to write
start transaction to make changes in the
project now we need to use this kind of
start and commit statements and we need
to put all our changes in between so
only if you're going to say for example
view name equals new name it's only
going to work if it's going to be
between start and commit and if you're
going to take it outside of it then
you're going to get an error that you
need a transaction to make it work all
right I'm going to remove it for
now and also a big note don't worry if
you make any changes between your start
and commit because it will be just roll
back which means just cancelled and
nothing will happen to your project so
whenever you have any issues you're
going to see the red text and usually
even your RIT won't crash you're just
going to see the message what's going
wrong and it's going to be canceled all
right we prepared our transaction now we
need to write for view in our selected
views and here two
things first of all we need to create
new view
name and then we need to rename our
views and also as you remember we need
to ensure that we have a unique view
name now to create a view name it's very
simple because we can read the existing
Name by using view name we're going to
write here old name equals view name now
the new name is going to be be our old
name we're going to write here replace
then we take our keyword for the find
keyword for the
replace and if you also work with suffix
and prefix we're just going to add it in
the end or we're going to add it in the
front and that's how we're going to
create a new name but we still don't
know if this name is going to be unique
enough and we're going to do this while
we are renaming cuz in here we're going
to set for example VI name equals new
name cuz this is a writable property and
we can see it in documentation right
there there it says get and set and set
means that we can write it like this I'm
going to assign a name if it's a unique
name it's going to work just fine but if
it's not we're going to get an error and
that's not good so for that we want to
use try and accept statements just to
catch our
errors and the way we're going to also
handle it I'm going to create here for I
in range of 20 so I'm going to give 20
tries to rename my view and every time
that I fail I'm going to do something
with a new name I'm going to write here
new name equals I'm going to keep adding
the star symbol in the end so for
example if you already have a view name
called floor plan it'll try to add one
star then the second the third and so on
so on so on until it reaches the
20 and the reason also I use the full
Loops cuz if we're going to use the
while loop and we forget to write The
Brak statements you're going to crash
your rabit cuz you're going to create an
infinite Loop and you cannot really
Escape that so therefore highly
recommend you to stick to the follow
Loops make here some kind of crazy
number and it's going to be still quick
to wait 200 times instead of waiting
this infinite Loop which never
ends all right and I think that we have
everything that we need and now let's
quickly recap what did we do so first of
all we select our views we either select
them in a project browser or we prompt
user to select by using p RIT forms
select views then we ensure that we have
some views before we're going to go any
further then we're going to Define our
renaming rules we're going to find our
floor plan we're going to replace it
with level just to make sure let's
actually make it EF level
in the prefix I'm going to add pre and
in the suix we're going to add maybe
something like
suf then we're going to start a
transaction and we're going to iterate
through all the selected views we need
to get our old name and we need to
Define our new name then we're going to
rename all of the views and then
eventually when it happens what's
important is that you make here a break
statement and before that we can also
make some print statement for example it
was this and it became this and let's
assign it this was old name and this is
our new name also I forgot to remove the
zero I don't want a 200 and again this
break statement if you don't do this
still going to work just going to kind
of rename it 20 times instead of one but
if you're going to put it here it's
going to stop executing this full loop
the moment is going to rename this view
So This is highly recommended to use The
Brak statement all right and in the end
we're going to write something like done
just so users know that we finished
renaming our views and maybe let's also
print 50 dashes
all right this is the code and you can
see it's not that complicated yes you do
need to know how to get your selections
what kind of forms available in py RIT
how to create transaction how to rename
it but this is things that you pick up
really quick and when you're going to
create your next tool you already know
about all of these Concepts you're just
going to have a look here and you're
easily going to replicate it now let's
go to ravit and see first of all I'm
going to select a few views like this in
my project browser and I'm going to
click on rename views and the moment I
do this you can see that they all added
the prefix suffix and floor plan was
replaced with the EF level and here are
the results this is what it was before
this is what happened after that and
listen guys understand that this is not
the most userfriendly experience right
to open your code change something here
most of you users will never do that I
know that for a fact instead of that I'm
going to put here like 2 a and this was
our version for the
development and now here I'm going to
create version 2 b
and I'm going to past snipp it right
here if you're going to write in Google
RPV Flex form eventually you're going to
end up on this website and in there you
have a very good example of how to
create custom forms first of all we need
to define components and you can see I
have a bunch of different labels right
here with the names and this is going to
be just shown as a text we're going to
see in the form prefix find replace and
so on and we're going to Define text
boxes this is where users can write
something and we're going to give names
to these text boxes so later on we can
actually get the values so we're going
to create a form we're going to show it
to the user then user going to interact
with it and we will be able to get the
values from the form and this is going
to be just a
dictionary so therefore we can get all
the values from dictionaries like this
and you can see all the keys we Define
them right here for the text boxes now I
think everything is exactly like I
wanted let's close this click on this button
button
again I'm going to select all of my views
views
click on select and now I get this form
as a prefix I'm just going to write ABC
and a Dash then in defined I'm actually
going to be looking for the EF with a
dash and I'm going to replace it with
nothing I just want to get rid of this
EF and in the suffix we're not going to
put anything and now we're going to
click on rename views and you can see
here are the print statements and All My
Views I changed I have my abc prefix EF
is gone and everything happened exactly
like I wanted all right then
congratulations now you know how to
create new Tools in pirate and it's just
the beginning as you will discover many
ideas that will help you in your daily
work start small and focus on quantity
over quality at first and over time
you'll create so many different tools
and have so much code examples that
creating new tools will be so much
easier in my case for example I can
create new tools where I copy paste more
than 80% of the code from previous tools
because I have so many examples already
and so will you I want to wish you keep
creating more cool tools and happy
coding and also I would like to ask you
for a favor if you've enjoyed my EFI
ravit starter kit it would make my day
if you would leave me a testimonial this
will help me promote this free stter kit
to even more people and motivate others
to give it a try and also I'll provide
you a nice reward if you decide to make
video testimonials so it's a win-win
situation you can leave this testimonial
by clicking here on leave a review or
going straight to this website and here
you can create your testimonial it's
100% appreciated and 0% % expected enjoy
your free pit starter kit and happy
coding it's 100% appreciated and 0%
expected enjoy this EF starter kit and
my name is Eric Fritz and I'll wish you
Click on any text or timestamp to jump to that moment in the video
Share:
Most transcripts ready in under 5 seconds
One-Click Copy125+ LanguagesSearch ContentJump to Timestamps
Paste YouTube URL
Enter any YouTube video link to get the full transcript
Transcript Extraction Form
Most transcripts ready in under 5 seconds
Get Our Chrome Extension
Get transcripts instantly without leaving YouTube. Install our Chrome extension for one-click access to any video's transcript directly on the watch page.