Yien
March 19, 2019, 8:29pm
1
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:
You need to instantiate your options object first, then set its DetachFromCentralOption property.
Its DetachFromCentralOption requires a DetachFromCentralOption enum and you need to assign it to the property (so you need to use the = statement)
To obtain the Application object use the active document Application property
Call OpenDocumentFile from your Application object as its not a static method
4 Likes
Yien
March 19, 2019, 8:58pm
3
wow that was quick!
the points 2 and 3 were not explain that well in the API docs.
again, thank you Thomas!
1 Like
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
Finally found it. I was looking for this like one week. Not only the code, but also the explanation teaching to fish. Thanks