openDocumentFile

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

1 Like

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
4 Likes

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

again, thank you Thomas!

1 Like

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

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