Cannot open BIM 360 based project with OpenDocumentFile Method
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello Forum,
I created a Dynamo Node containing some python code using the OpenDocumentFile Method to open Revit files. This method does not activate it, so it just opens it in the background. This is what I want.
The code works just fine when opening local files, but when I try to open a BIM 360 model, something RevitAPIDocs.com claims should be possible, Revit ruins it by throwing an exception: “A managed exception was thrown by Revit or by one of its external applications." So it seems to me that my code is fine, but that Revit does not allow me to open a BIM 360 file this way. Is there a way to get Revit to listen and do as I say?
Below is my code:
import clr
import sys
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
#curdoc = __revit__.ActiveUIDocument.Document
revit = DocumentManager.Instance.CurrentUIApplication.Application
filepath = IN[0]
if filepath[-4:] != ".rvt": filepath += ".rvt"
docfile = ModelPathUtils.ConvertUserVisiblePathToModelPath(filepath)
openoptions = OpenOptions()
openoptions.Audit = False
openoptions.DetachFromCentralOption = DetachFromCentralOption.DoNotDetach
openoptions.AllowOpeningLocalByWrongUser = False
try:
opened = revit.OpenDocumentFile(docfile, openoptions)
openmessage = "Successful"
except:
opened = sys.exc_info()[1]
openmessage = "Unsuccessful"
if openmessage == "Successful":
close = TaskDialog.Show("MyCompany", openmessage + ": " + str(opened) + "Would you like to close the file now?", TaskDialogCommonButtons().Yes | TaskDialogCommonButtons().No, TaskDialogResult())
if close == TaskDialogResult.Yes:
closed = opened.Close(False)
if closed:
TaskDialog.Show("MyCompany", "Closed Successfully")
else:
TaskDialog.Show("MyCompany", "Could not close document; Strongly Recommended to restart Revit Application")
else:
TaskDialog.Show("MyCompany", "File still open in the BackGround")
else:
TaskDialog.Show("MyCompany", openmessage + ": Error: " + str(opened))
OUT = 0
The filepath looks like this:
BIM 360://My Project/My Project File_R20.rvt
Any suggestions are welcome!
Thanks