# openDocumentFile

**URL:** <https://forum.dynamobim.com/t/opendocumentfile/33725>\
**Category:** Revit\
**Tags:** python, api\
**Created:** [March 19, 2019, 8:29pm UTC](https://forum.dynamobim.com/t/opendocumentfile/33725 "2019-03-19T20:29:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yien](https://avatars.discourse-cdn.com/v4/letter/y/ecd19e/32.png) [@Yien](https://forum.dynamobim.com/u/Yien)\
**Post date:** [March 19, 2019, 8:29pm UTC](https://forum.dynamobim.com/t/opendocumentfile/33725/1 "2019-03-19T20:29:36Z")

</div>

hi guys,

im trying to get the document with Python, but im stuck at the OpenDocumentFile…

here’s the script.

import clr

clr.AddReference("RevitServices")  
from RevitServices import\*  
import RevitServices  
from RevitServices.Persistence import DocumentManager  
from RevitServices.Transactions import TransactionManager

clr.AddReference("RevitAPI")  
import Autodesk  
from Autodesk.Revit.DB import\*  
from Autodesk.Revit import ApplicationServices

Path = ModelPathUtils.ConvertUserVisiblePathToModelPath(IN[0])  
Options = OpenOptions().DetachFromCentralOption.DetachAndPreserveWorksets

file = ApplicationServices.Application.OpenDocumentFile(Path,Options)

OUT = Options

and i got in the output : File “”, line 20, in   
TypeError: expected Application, got FilePath

i know there is a node in Rhythm, but any help would be nice.

thank you

---

<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:** [March 19, 2019, 8:46pm UTC](https://forum.dynamobim.com/t/opendocumentfile/33725/2 "2019-03-19T20:46:56Z")

</div>

Hi @Yien I hope you’re well.

Try this:

```
import clr

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

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument
app = doc.Application

filePath = IN[0]
modelPath = ModelPathUtils.ConvertUserVisiblePathToModelPath(filePath)

options = OpenOptions()
options.DetachFromCentralOption = DetachFromCentralOption.DetachAndPreserveWorksets

docOnDisk = app.OpenDocumentFile(modelPath, options)

OUT = docOnDisk

```

There were a few updates required:

1. You need to instantiate your options object first, then set its DetachFromCentralOption property.
2. Its DetachFromCentralOption requires a DetachFromCentralOption enum and you need to assign it to the property (so you need to use the = statement)
3. To obtain the Application object use the active document Application property
4. Call OpenDocumentFile from your Application object as its not a static method

---

<div class="post-metadata">

**Author:** ![Yien](https://avatars.discourse-cdn.com/v4/letter/y/ecd19e/32.png) [@Yien](https://forum.dynamobim.com/u/Yien)\
**Post date:** [March 19, 2019, 8:58pm UTC](https://forum.dynamobim.com/t/opendocumentfile/33725/3 "2019-03-19T20:58:25Z")

</div>

wow that was quick!  
the points 2 and 3 were not explain that well in the API docs.

again, thank you Thomas!

---

<div class="post-metadata">

**Author:** ![ruben.romero](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ruben.romero/32/115842_2.png) [@ruben.romero](https://forum.dynamobim.com/u/ruben.romero)\
**Post date:** [April 29, 2021, 5:50pm UTC](https://forum.dynamobim.com/t/opendocumentfile/33725/4 "2021-04-29T17:50:47Z")

</div>

> [@Thomas\_Mahon](#):
>
> a few updates required

Would be good to create the script to handle input as a list instead of a single index input. Thanks anyways very useful

---

<div class="post-metadata">

**Author:** ![rafaelPD66Z](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@rafaelPD66Z](https://forum.dynamobim.com/u/rafaelPD66Z)\
**Post date:** [February 26, 2024, 11:45pm UTC](https://forum.dynamobim.com/t/opendocumentfile/33725/5 "2024-02-26T23:45:23Z")

</div>

Finally found it. I was looking for this like one week. Not only the code, but also the explanation teaching to fish. Thanks
