# Node with Revit API - how get access to current document?

**URL:** https://forum.dynamobim.com/t/node-with-revit-api-how-get-access-to-current-document/56078
**Category:** Developers
**Tags:** revit, api
**Created:** [October 11, 2020, 9:09am UTC](https://forum.dynamobim.com/t/node-with-revit-api-how-get-access-to-current-document/56078 "2020-10-11T09:09:51Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![georg.grebenyuk](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/georg.grebenyuk/32/169424_2.png) [@georg.grebenyuk](https://forum.dynamobim.com/u/georg.grebenyuk)
#### Post date: [October 11, 2020, 9:09am UTC](https://forum.dynamobim.com/t/node-with-revit-api-how-get-access-to-current-document/56078/1 "2020-10-11T09:09:51Z")

</div>

Hi, I continue researching creation nodes based C# to Dynamo and wanted try nodes that used Revit API - f.e. below simple node that take parameters of Revit’s base point and return them

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/3/e395647ab3d74e64f66f3c63a6fef39038433f8c.jpeg)  
Main problem- how I can determine current document?! I tried use Dynamo’s “Document.Current”, but that Dynamo’s command (non Revit API) and smb on forum adviced me use libraries that conver Dynamo commands/API to Revit API and on that step I stucked.  
Have anybody ideas how it must working?  
If I use classic operations as in Revit’s plugin:

```
public Autodesk.Revit.UI.Result Execute(ExternalCommandData revit, ref string message, ElementSet elements)
{ UIApplication app = revit.Application;
Document doc = app.ActiveUIDocument.Document;
....}

```

Dynamo will wait for me values for variables in (…)  
I will be glad any help!

* * *

All code below  
using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
using System.Threading.Tasks;

```
using Autodesk.Revit.DB;
using Autodesk.DesignScript.Runtime;

namespace BasePoint_coord1
{

    public class RevitAPI
    {
        [MultiReturn(new[] { "BasePoint_X", "BasePoint_Y", "BasePoint_Z", "BasePoint_Angle" })]
        public static Dictionary<string, object> GetCoordOfRevitBasePoint(Autodesk.Revit.DB.Document doc)
        {
            var basePoint = new FilteredElementCollector(doc).OfClass(typeof(BasePoint)).Cast<BasePoint>().Where(p => !p.IsShared).ToList().FirstOrDefault();
            //Инициация параметров
            double BasePoint_X = 0;
            double BasePoint_Y = 0;
            double BasePoint_Z = 0;
            double BasePoint_Angle = 0;

            //Присвоение переменным значений
            BasePoint_Y = basePoint.get_Parameter(BuiltInParameter.BASEPOINT_NORTHSOUTH_PARAM).AsDouble();
            BasePoint_X = basePoint.get_Parameter(BuiltInParameter.BASEPOINT_EASTWEST_PARAM).AsDouble();
            BasePoint_Z = basePoint.get_Parameter(BuiltInParameter.BASEPOINT_ELEVATION_PARAM).AsDouble();
            BasePoint_Angle = basePoint.get_Parameter(BuiltInParameter.BASEPOINT_ANGLETON_PARAM).AsDouble();

            //string result = BasePoint_Y + "," + BasePoint_X + "," + BasePoint_Z + "," + BasePoint_Angle;
            return new Dictionary<string, object>
            {
                {"BasePoint_X", BasePoint_X},
                {"BasePoint_Y", BasePoint_Y},
                {"BasePoint_Z", BasePoint_Z},
                {"Angle of rotation", BasePoint_Angle},
            };
        }
    }
}
```

---

<div class="post-metadata">

### Author: ![Alban\_de\_Chasteigner](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/alban_de_chasteigner/32/39650_2.png) [@Alban\_de\_Chasteigner](https://forum.dynamobim.com/u/Alban_de_Chasteigner)
#### Post date: [October 11, 2020, 10:37am UTC](https://forum.dynamobim.com/t/node-with-revit-api-how-get-access-to-current-document/56078/2 "2020-10-11T10:37:08Z")

</div>

Hi @georg.grebenyuk,

You can generate a Revit.DB.Document with a simple python script :

```
import clr
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager

OUT = DocumentManager.Instance.CurrentDBDocument

```

 ![Doc](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/b/cb7859a8bd849fe43285d776653f52c49ded39d8.png)

---

<div class="post-metadata">

### Author: ![georg.grebenyuk](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/georg.grebenyuk/32/169424_2.png) [@georg.grebenyuk](https://forum.dynamobim.com/u/georg.grebenyuk)
#### Post date: [October 11, 2020, 11:30am UTC](https://forum.dynamobim.com/t/node-with-revit-api-how-get-access-to-current-document/56078/3 "2020-10-11T11:30:47Z")

</div>

Hi, @Alban_de_Chasteigner  
If I done as you said - I will get an error:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/f/8fc4aaaeb5c36c29d087c89f770750978269fc2e.jpeg)

---

<div class="post-metadata">

### Author: ![Thomas\_Mahon](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/thomas_mahon/32/64209_2.png) [@Thomas\_Mahon](https://forum.dynamobim.com/u/Thomas_Mahon)
#### Post date: [October 11, 2020, 12:39pm UTC](https://forum.dynamobim.com/t/node-with-revit-api-how-get-access-to-current-document/56078/4 "2020-10-11T12:39:00Z")

</div>

Your dictionary keys - specifically your “Angle of rotation” key - doesn’t match the keys you’ve declared in your MultiReturn attribute. Change it to “BasePoint\_Angle” and you wont get the exception.

---

<div class="post-metadata">

### Author: ![georg.grebenyuk](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/georg.grebenyuk/32/169424_2.png) [@georg.grebenyuk](https://forum.dynamobim.com/u/georg.grebenyuk)
#### Post date: [October 11, 2020, 3:07pm UTC](https://forum.dynamobim.com/t/node-with-revit-api-how-get-access-to-current-document/56078/5 "2020-10-11T15:07:33Z")

</div>

Yeah, it working!  
But how I can get access to current document from C# without that temp-decision with 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: [October 11, 2020, 3:50pm UTC](https://forum.dynamobim.com/t/node-with-revit-api-how-get-access-to-current-document/56078/6 "2020-10-11T15:50:22Z")

</div>

This could help:

> **[ActiveDocument Property](https://www.revitapidocs.com/2020/c9769a52-5a67-3f36-e10c-676617376366.htm)**
>
> Online Documentation for Autodesk's Revit API: 2015, 2016, 2017, 2017.1, 2018

---

<div class="post-metadata">

### Author: ![georg.grebenyuk](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/georg.grebenyuk/32/169424_2.png) [@georg.grebenyuk](https://forum.dynamobim.com/u/georg.grebenyuk)
#### Post date: [October 11, 2020, 5:36pm UTC](https://forum.dynamobim.com/t/node-with-revit-api-how-get-access-to-current-document/56078/7 "2020-10-11T17:36:13Z")

</div>

I’m glad for that link, but I can’t understand how it can help me.  
I tried some variants with that function and other and main result that I get - nothing methods are not visiable in Dynamo!  
I’m amazing why there are no any info on [https://developer.dynamobim.org](https://developer.dynamobim.org) how get access to Revit from Custom Node?

---

<div class="post-metadata">

### Author: ![Thomas\_Mahon](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/thomas_mahon/32/64209_2.png) [@Thomas\_Mahon](https://forum.dynamobim.com/u/Thomas_Mahon)
#### Post date: [October 11, 2020, 6:47pm UTC](https://forum.dynamobim.com/t/node-with-revit-api-how-get-access-to-current-document/56078/8 "2020-10-11T18:47:59Z")

</div>

It all depends on what you want to do. @jacob.small suggestion cant be used with zero touch nodes and is only avialable if you are writing Revit addins which implement IExternalCommand.

So you need to establish the following: does your node _even_ need the document as an input? Some custom nodes do have the document as an input in case where they support links for example, but this is a nuisance since these packages also need to add extra nodes to return the RevitAPI document like what @Alban_de_Chasteigner demonstrated as there is no way for developers to create an instance of Dynamo’s `Revit.Application.Document` document wrapper as its a singleton (uses the singleton pattern) and therefore has no public constructor.

The problem with returning RevitAPI entities in Dynamo is they are not compatible with any OOTB node or most other packages which means any OOTB node requiring a document will fail in the same way your node is failing if the RevitAPI document from a custom node is used with an OOTB node…which is extremely confusing to most users who are not going to be concerned with these nuances.

If you don’t need the input, then you can access the document via Dynamos singleton stored in its DocumentManager class. This is the most common method zero touch and python nodes use to access the active document, and you can simply add this line inside your method and therefore avoid the need to provide an input:

`var document = DocumentManager.Instance.CurrentDBDocument;`

Alternatively, if you do want to provide the document input then you need to qualify the class or use an alias using directive which specifies Dynamo’s document wrapper as shown below, but its kind of pointless given the above basically does the same thing but avoids the need for an input:  
`public static Dictionary<string, object> GetCoordOfRevitBasePoint(Revit.Application.Document doc)`

---

<div class="post-metadata">

### Author: ![georg.grebenyuk](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/georg.grebenyuk/32/169424_2.png) [@georg.grebenyuk](https://forum.dynamobim.com/u/georg.grebenyuk)
#### Post date: [October 11, 2020, 7:59pm UTC](https://forum.dynamobim.com/t/node-with-revit-api-how-get-access-to-current-document/56078/9 "2020-10-11T19:59:48Z")

</div>

Thank you very much!  
After I added link to “C:\Program Files\Autodesk\Revit 2020\AddIns\DynamoForRevit\Revit\RevitServices.dll” and added “using RevitServices.Persistence” all realy starting working  
Also I start research your [guide](https://forum.dynamobim.com/t/become-a-dynamo-zero-touch-c-node-developer-in-75-minutes/28007) - there are a lot of interestind data for me 😀
