Hang tight while we fetch the video data and transcripts. This only takes a moment.
Connecting to YouTube player…
Fetching transcript data…
We’ll display the transcript, summary, and all view options as soon as everything loads.
Next steps
Loading transcript tools…
My pyRevit Template for Revit API: A Step-by-Step Guide [EP. 5/10] | Erik Frits | YouTubeToText
YouTube Transcript: My pyRevit Template for Revit API: A Step-by-Step Guide [EP. 5/10]
Skip watching entire videos - get the full transcript, search for keywords, and copy with one click.
Share:
Video Transcript
Video Summary
Summary
Core Theme
This lesson focuses on understanding the anatomy of PyRevit scripts and preparing reusable Revit templates to streamline future tool development, covering essential script elements, metadata tags, and best practices for efficient coding.
Mind Map
Click to expand
Click to explore the full interactive mind map • Zoom, pan, and navigate
hi everybody Welcome to the fifth lesson
of learn ra API course in this lesson
we're going to talk about pyate script
anatomy and we're going to prepare P
Revit templates for you so you can use
them in all your future tools and you
never have to start with the blank page
and also to save time during this lesson
we will also start with my existing
templates and I will break them down
step by step because in the end of the
day you probably will start with them
anyway and then slowly you will adjust
them to your own needs but I will also
mention in the end P developers
documentation where you can find even
more information now without further Ado
let's actually jump straight into the
code and I'm going to explain it well in
ravit open the extension that you
created in the previous lessons and then
you're going to find template paray with
minimum this are the two templates I'm
going to start with the minimum version
because this one is an Overkill it also
has a ton of comments because it's it
was made for educational purpose but
this one is actually what I use all
right and in this template the first
line is utf8 encoding and in Iron python
we have to specifically declare that we
want to use d8 encoding CU for example
if you would use uh some kind of German
Russian or non-standard asky characters
and you don't have this line right here
you'll notice that it's highlighted if
you're going to hover over it's going to
say that non asking character U is in
the file and it's going to cause an
error and it's also going to give you a
very weird error message which is not
very easy to debug I think so just to
avoid this always use this utf8 encoding
even if you're not using Russian German
or whatever characters you think of
then the next is the title and it's just
the name of the button that you're going
to see in ravit UI there's also a way to
define different names for different
ravit languages but I'm going to show it
later then the dock is the description
that you're going to see in ravit when
you're going to hover over your buttons
for example when I hover over this
you'll see there's a version date
description how to to- do last updates
and auor and I really like to put all of
this information because it's going to
help your users understand in short what
what is this button doing how to
actually use it and how to is a very
important part cuz often times you will
have scripts where you're going to
describe first select walls then click
on the button select W type and then
this happens and without that your users
might not understand how to use it
correctly also depends on what kind of
tools you make last update also nice so
you can keep track of what kind of
changes did you make and what you want
to also do in the future now the next is
import and in here we just put our most
used import so we don't have to write it
over and over and in pretty much every
every tool that you're going to make
you're going to write from Autodesk
gravy DB import something we probably
need to import it in every single script
and also don't bother to importing only
the classes that you're actually going
to use cuz even though people say yes
it's going to execute faster you will
never notice this difference because we
talk about fraction of a fraction of a
second so just import everything and don't
don't
care however there are also other name
spaces for other disciplines example if
I'm going to write Auto disk gravy DB
notice there structure architecture
steel event analysis electrical there is
also lighting mechanical and so on so on
so on and if you work in one of these
disciplines there's a good chance that
you would need to import something from
the structure like for example
structural type is very common when you
create families maybe you want to import
something from Autodesk rdb architecture
cuz I know there are classes like room
there is stairs there is railings and
all of this if you often use these
classes then it makes sense but if not
don't have to make it part of your
template just know that there are this
name spaces from where more classes come
then this one is actually very important
and I highly recommend you to keep it in
all your templates because in Revit API
documentation you will often see that we
need arguments which is I list or I
collection and this has mean that we
need to provide a typed list and this is
how we get it we get it from system
collection generic import list and the
difference is that if we going to create
for example list of element IDs in
Python but also in the same python list
we can add the integer we can add our
string we can add maybe another list
with numbers and so
on but what type list do is you can
Define element IDs I need you to create
a list where only element ID types can
be inside then this is how you would
create an empty list and if you would
have your element IDs you could just
take it and provide it here inside like
this or you can use add method if you're
for example in full loop and you want to
add one by one by one for example this
one will add one element okay this is
just an example just leave it here
because often times you would have to
use it then there are variables there
are three common variables that you need
you need a doc UI do and app this one
stands for the document and it
represents your project you would need
it whenever you want to make changes in
your project when you want to get
elements out of your project or
something related to this specific
project your ID do is all about ravit UI
and for example this is common to use
when you want to prompt user to select
something or get user selection or
something related to the user interface
lastly application relates to the ravit
application itself this is from where
you can get ravit year version maybe
background color and maybe where is the
path to the shared parameter file and
this kind of application related
parameters but also I highly recommend
you to set the type hinting here and you
can do this in Python like this you make
a comment with type and then you define
the class the reason you do that because
when you're going to use this variable
you definitely want to have some kind of
auto complete for example if I'm going
to write active I can see there's active
view if I want to for example maybe load
a family then I can use it click on
control Q in pie charm and see some
documentation how it works but if you're
going to remove this and you're going to
try to for example doc active view it's
not going to give you any suggestions
because py charm doesn't know what it is
because py charm doesn't know what is
this special variable uncore ravit but
py RIT and ravit python show they know
what it is therefore definitely ly leave
this kind of type hinting here this one is
is
document then this one is the class of
UI document and this one is the type of
application you'll also notice this one
highlighted this is because we not
reference this classes cuz we have to
import them and one comes from
Autodesk ravit UI import UI document and
other comes from Autodesk RIT
I think application Services import
application yeah something like this
you'll have to import them as well and
listen this one you don't really need
because you don't use Ab that often I
just like to have it here but U ID do if
you want to have type hinting definitely
import it if you don't want to type
hinting then you can remove it but I
would just leave it cuz for beginners
it's amazing now then you'll notice that
I have some blocks like functions and
Main and these are the blocks that I
personally use I haven't seen any other
programmers use these kind of blocks
because normally majority of people they
create a comment write their variables
and maybe they make some
dashes I also use this once in a while
but I also use the emojis then to make
emojis you click on the start key which
makes this kind of start appear and
together with a DOT and then you're
going to find a various emojis you can
choose from but if you want to make
these blocks this is called ask Art and
you need a special plugin and it's both
available in pie charm and in Visual
Studio code person personally I find
them very useful on large scripts but on
the smaller ones they actually take
quite a lot of space but if you want to
learn how to do them click here on the
file then scroll down to the
settings and then we need to open
plugins right here in marketpl look for
the plugin called figlet it looks like
this and just click on install it I
already installed it and you can see in
there there's like preview of what it
is now to use it in py charm we would
create a comment like this
I'll write here something like new
comment select this text and then you
have to hold alt and click on insert key
you'll see this menu and you can select
asky art then you would also have to
define the font because you will notice
that there are a lot of different fonts
for this asky art the one that I use you
would have to click on more and then
scroll here until we can see here somewhere
Kelvin and right there is Kelvin s this
is the phone that I use for these
special blocks I haven't seen anyone
except me using it and if you like them
you're welcome to use it as well but if
not regular comment is fine it's just
whatever is your
preference and yeah that's pretty much
it about minimum template we have our
name and description we have the most
common Imports we use and we keep here
the variables that we need for ravit API
I highly recommend you to use the type
hinting for the document and maybe UI
document for the application you don't
need the type hinting and then if you
work in large scripts consider making
functions Main and so on so you can kind
of separate your code visually with
these blocks listen this template is
going to be more than enough for
majority of you and just adjust it to
your old needs but also it's really good
to know that pyate provides a few meta
attacks that you might be interested in
in this example you can see all about
them in there you can see you can
provide the author you can provide help
URL and let's actually open this anatomy
of iron python I showed you earlier I'm
going to put it here on the side and
listen I'm going to scroll through and
just go through the very quick help URL
is really useful because you can hover
over any button click on F1 and it's
going to open whatever URL or path to a
special file for example if you have a
button and you have a PDF on how to use
special script and users can hover click
on F1 and they going to open either the
PDF or YouTube video that you provide
here then the next one is highlight and
if you scroll here you'll see that we
can either highlight elements as new or
updated I just going to add this kind of
orange dot in the corner and when you
hover over you're also going to see in
the tool see whether it's new or updated
it might be good to direct a little bit
more attention to new buttons then the
next one we can limit our minimum and
maximum Revit version and it's useful
when we have Revit API limitations for
example we couldn't create ceilings
before Revit 2022 I know it sounds
stupid but that was the case therefore
we could Define here that the minimum
version is 2022 and the maximum is 2025
or maybe we just remove it all together
so we allow all versions after that this
way the button is going to be shown in
22 and higher versions and in ravy 2021
it's not going to be shown at
all then we have context and this is
something special uh I can see it right
here as well context and it also has its
own kind of bundle context with the
description this context allows you to
set some criteria what should happen
before your button can be executed let
me show you what it means we're just
Rit for example let's open this push button
button
let's open the script and somewhere here
we're going to create
context I'm going to write selection
because you can see it's in here
selection you also notice that all of
the syntax in in the yaml format and
this is for the bundle that yaml file
I'm going to explain it in just a second
let me just explain the context first so
I put here selection which is one of the
special kind of keywords and then in
ravit I'm going to reload my P RIT so
all the changes happen to this
button and then have a look when I'm
going to go here you can see push button
is grayed out and I cannot really click
on it no matter how hard I try but if
for example I'm going to select a wall
and go back there now I can click on
this button so with this selection you
can Define what kind of elements have to
be selected if anything have to be
selected maybe you have to be on a
special view but and you can read more
about it in the bundle context you go to developers
developers
documentation let me make it bigger then
you scroll down and right here is the bundle
bundle
context so inside you can see you can
provide some category you can provide
multiple categories you can provide
selection zero do here you can provide
what kind of document it's made for is
it project workshare Cloud family what
kind of active view you need to provide
active drafting view plan sheet whatever
you want and then there's also Advanced
one where you can combine any all and so
on and you can see that all the syntax
is actually made for bundle. yaml file
to use that going to come to wherever
your button is placed I we need to
create a new file right here
I'm going to click on new then let's
create some kind of text document I'm
going to write bundle. yaml just make
sure you change the file format and if
you don't see this click here on The
View show and you can show the file name
extensions to change it inside I'm just
going to drop it like it is and click on
Save also keep in mind that in here you
can provide more than just the context
you can also put your the name of the
button the description of the button and
it might be useful only if you want to
provide it in multiple languages but but
honestly I never use it myself for
example here when I click on bundle
metadata you can see here's an example
and this is what we could add inside
here's how would add here a title or
maybe title in multiple language the
description the highlight and so on so
on so on you can add much more than just
the context but honestly I never use the
bundle that yaml file and I don't
recommend to any beginners because I
find it much nicer if you have all the
meta taxs right here example in this
file you have them all here this is very
quick and easy to find and change change
them if you need to but with bundle.
yaml you have to come here and open another
another
file now context all right also before
we're going to go further remove context
from the file because now we have it in
the file and in the bundle we just want
to have it in the
bundle now we're going to go to pyit and
reload it and while it's reloading let's
have a look what did we set we said that
it has to be active floor plan and we
have to have selection either walls or
floors we're going to see if it works now
now
now I actually got some kind of error
I'm not sure why it
happens but honestly I never use the
bundle that yaml file for my scripts
because I don't like separate this meta
tax from the script and also sometimes
you're going to get some kind of Errors
if you're going to misspell it like I
show you right now errors reading
metadata file I also may be doing it
wrong but honestly I don't recommend it
to any beginners yes you can limit the
button access depending on what's
selected but I find it so much better if
users click on the button and if they
don't have anything selected I just make
a kind of pop-up menu saying hey you
have to select the wall to do X Y and Z
or maybe if they don't have anything
selected I'm just going to prompt them
to select something and write hey select
walls now instead of just disabling the
button and they don't know why it's
disabled how to activate it because they
cannot really even hover over it as you
can see in here I hover over it okay I
get the description but it's really
confusing to see grade out buttons and
users just kind of think that okay
probably button is disabled or whatever
therefore I don't really recommend to
use context I don't really recommend
using bundle. yaml files but you welcome
to use them if you see value in
them all right and now you have your
templates and you know about PIR meta
attacks and that they provide you
additional functionality now you're
ready to create your first ravit addin
using ravit API and that's exactly what
I will teach you in the next lesson I'll
keep that example somewhat intermediate
so we can create something more fun and
more useful and then in the next modules
of this course I'll break down all ravit
API Concepts one by one so you can learn
them without feeling overwhelmed and I
will first focus on the theory and then
I'm going to provide you how to apply
this theory in practice so I wish you
happy coding and I will see you in the
next lesson where we're going to create
a really cool tool together see you there
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.