# Revit API for Python

**URL:** <https://forum.dynamobim.com/t/revit-api-for-python/1544>\
**Category:** FAQ\
**Created:** [May 27, 2015, 6:41pm UTC](https://forum.dynamobim.com/t/revit-api-for-python/1544 "2015-05-27T18:41:15Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Question\_Marc](https://avatars.discourse-cdn.com/v4/letter/q/22d042/32.png) [@Question\_Marc](https://forum.dynamobim.com/u/Question_Marc)\
**Post date:** [May 27, 2015, 6:41pm UTC](https://forum.dynamobim.com/t/revit-api-for-python/1544/1 "2015-05-27T18:41:15Z")

</div>

Hi,

I just started learning python and I would like to use it at work. I already played around with Rhino Python Script, and it was very intuitive and fun experience. Now I’m trying to write some code for dynamo Python node, but I just don’t know where to start. I’ve already found the [revitapisearch.com](http://revitapisearch.com) , but those commands are not for Python - there is only C#, Visual Basic and Visual C++. So as I understand, this won’t work with Dynamo Python node nor PythonShell, right? Or am I being stupid? Could someone give me a simple example how to, lets say, create a reference point in specified coordinates with Python? I just need a piece of a simple code to see how it should be done. Is there any way I could use revitapisearch with python?

&nbsp;

Best

---

<div class="post-metadata">

**Author:** ![Dimitar\_Venkov](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/dimitar_venkov/32/2068_2.png) [@Dimitar\_Venkov](https://forum.dynamobim.com/u/Dimitar_Venkov)\
**Post date:** [May 27, 2015, 10:25pm UTC](https://forum.dynamobim.com/t/revit-api-for-python/1544/2 "2015-05-27T22:25:13Z")

</div>

Hi,

Have you had a chance to check out the python guide for 0.7?

> **[DynamoDS/Dynamo](https://github.com/DynamoDS/Dynamo/wiki/Python-0.6.3-to-0.7.x-Migration)**
>
> Open Source Graphical Programming for Design. Contribute to DynamoDS/Dynamo development by creating an account on GitHub.

The last code snippet should work for reference points.

---

<div class="post-metadata">

**Author:** ![Question\_Marc](https://avatars.discourse-cdn.com/v4/letter/q/22d042/32.png) [@Question\_Marc](https://forum.dynamobim.com/u/Question_Marc)\
**Post date:** [June 2, 2015, 5:19pm UTC](https://forum.dynamobim.com/t/revit-api-for-python/1544/3 "2015-06-02T17:19:32Z")

</div>

Thank you, Dimitar. I have checked the examples from this article, and it was very helpful. However I have a problem with XYZ() - Python says it’s not been defined, whether I use doubles as coordinates or leave an empty bracket. Do you know what could be the cause? Does it have something to do with Revit version?

&nbsp;

Best

---

<div class="post-metadata">

**Author:** ![Andreas\_Dieckmann](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/andreas_dieckmann/32/365_2.png) [@Andreas\_Dieckmann](https://forum.dynamobim.com/u/Andreas_Dieckmann)\
**Post date:** [June 2, 2015, 10:55pm UTC](https://forum.dynamobim.com/t/revit-api-for-python/1544/4 "2015-06-02T22:55:32Z")

</div>

You are likely missing a reference to the Revit API like this:

import clr  
clr.AddReference(‘RevitAPI’)  
from Autodesk.Revit.DB import \*

You can find a lot of examples here:

> **[andydandy74/ClockworkForDynamo](https://github.com/andydandy74/ClockworkForDynamo/tree/master/nodes/0.7.x/python)**
>
> A collection of 400+ custom nodes for the Dynamo visual programming environment - andydandy74/ClockworkForDynamo

(These are all the Python scripts from package Clockwork extracted as separate files…)

---

<div class="post-metadata">

**Author:** ![Steven\_Hansen1](https://avatars.discourse-cdn.com/v4/letter/s/8797f3/32.png) [@Steven\_Hansen1](https://forum.dynamobim.com/u/Steven_Hansen1)\
**Post date:** [December 31, 2015, 12:57pm UTC](https://forum.dynamobim.com/t/revit-api-for-python/1544/5 "2015-12-31T12:57:01Z")

</div>

Question Marc, Were you able to solve your original post? I am just now starting and wold like to know if C# Scrips can be used or if there is an API library for Revit Python.

---

<div class="post-metadata">

**Author:** ![hzamaniM54WP](https://avatars.discourse-cdn.com/v4/letter/h/f0a364/32.png) [@hzamaniM54WP](https://forum.dynamobim.com/u/hzamaniM54WP)\
**Post date:** [August 16, 2017, 5:03am UTC](https://forum.dynamobim.com/t/revit-api-for-python/1544/6 "2017-08-16T05:03:16Z")

</div>

I know there’s no API library for Revit in Python. I heard from Ehsan Iran-Nejad that they are looking to implement some code samples & syntax in Python in [revitapidocs.com](http://revitapidocs.com). Nothing has been happening yet but I also have this question:

How do you know what to type in Python node for Revit API syntax that is in C# or C++ or Visual Basic?? 🤔

---

<div class="post-metadata">

**Author:** ![Konrad\_K\_Sobon](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/konrad_k_sobon/32/8838_2.png) [@Konrad\_K\_Sobon](https://forum.dynamobim.com/u/Konrad_K_Sobon)\
**Post date:** [August 16, 2017, 5:23pm UTC](https://forum.dynamobim.com/t/revit-api-for-python/1544/7 "2017-08-16T17:23:22Z")

</div>

Well, you just kind of know. Just type whatever you see in C# but using Python syntax. I don’t think there is an easy way to explain this. There are online syntax converters if you just google C# to Python.

---

<div class="post-metadata">

**Author:** ![hzamaniM54WP](https://avatars.discourse-cdn.com/v4/letter/h/f0a364/32.png) [@hzamaniM54WP](https://forum.dynamobim.com/u/hzamaniM54WP)\
**Post date:** [August 16, 2017, 11:29pm UTC](https://forum.dynamobim.com/t/revit-api-for-python/1544/8 "2017-08-16T23:29:00Z")

</div>

Thanks Konrad. I have used online converters but they don’t really provide a useful result. One of the instances which frustrated me a lot was using Revit API to get file version. I checked the documentation and found that we have the C# syntax below for that:

```
public string SavedInVersion { get; }

```

I guessed the syntax for Python would be:

```
Autodesk.Revit.DB.BasicFileInfo.SavedInVersion(filepath)

```

Which didn’t work. I tested a few other possibilities but still no luck. Then came across a Python node in Rhythm which does exactly that. By checking the code I found that we have this method to get SavedInVersion!!:

```
BasicFileInfo.Extract(i).SavedInVersion

```

in which i is a file path as string!

Full code is:

```
#Copyright(c) 2017, john pierson
items = IN[0]
typelist = list()
for i in items:
	try:
		typelist.append(BasicFileInfo.Extract(i).SavedInVersion)
	except:
		typelist.append(list())
		
OUT = typelist

```

Do I need more experience in Python to find these peculiarities? or should I be looking to learn C#?

---

<div class="post-metadata">

**Author:** ![Konrad\_K\_Sobon](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/konrad_k_sobon/32/8838_2.png) [@Konrad\_K\_Sobon](https://forum.dynamobim.com/u/Konrad_K_Sobon)\
**Post date:** [August 17, 2017, 12:15am UTC](https://forum.dynamobim.com/t/revit-api-for-python/1544/9 "2017-08-17T00:15:15Z")

</div>

There are different ways of getting file version. What John demonstrated is a way to get it without opening the file. There are ways to get it from currently open file etc.

Now, this is ALL really simple, but you have to have SOME rudimentary understanding of programming languages, class structure, method vs. property etc. When a programmer looks at `public string SavedInVersion { get; }` you immediately know that it’s a read only property of a `BasicFileInfo` class. This is ALL really obvious for someone who has at least a basic understanding of programming in C#. Translating that to Python, is again a matter of understanding basic principles of programming. To call a property on a class object, you have to first get or create an instance of that class. That’s exactly what John was doing.

Like I said, it’s pretty straight forward, but AFTER you have learned some basics of programming. I would suggest that you sign up for some intro classes to programming. Take C# as it’s more relevant to Revit, and Revit API is documented very well in that language. Once you learn that, it will be easy to translate to Python.

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [August 17, 2017, 1:43am UTC](https://forum.dynamobim.com/t/revit-api-for-python/1544/10 "2017-08-17T01:43:39Z")

</div>

_drops his Python class_  
_signs up for a C# class instead_

As always thanks for the words of wisdom @Konrad_K_Sobon!
