Cannot open BIM 360 based project with OpenDocumentFile Method

Cannot open BIM 360 based project with OpenDocumentFile Method

LucasJonnedeJong
Enthusiast Enthusiast
4,396 Views
15 Replies
Message 1 of 16

Cannot open BIM 360 based project with OpenDocumentFile Method

LucasJonnedeJong
Enthusiast
Enthusiast

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

0 Likes
4,397 Views
15 Replies
Replies (15)
Message 2 of 16

LucasJonnedeJong
Enthusiast
Enthusiast

So, 76 views, noone has a clue?

0 Likes
Message 3 of 16

TripleM-Dev.net
Advisor
Advisor

Hi,

 

I think you need another overload option: 

OpenDocumentFile Method (ModelPath, OpenOptions, IOpenFromCloudCallback) 

 

Only available from Revit 2020 and up.

0 Likes
Message 4 of 16

TripleM-Dev.net
Advisor
Advisor

And, see post:

https://thebuildingcoder.typepad.com/blog/2018/04/whats-new-in-the-revit-2019-api.html#4.1.5 

 

now offer the ability to open a C4R model from its location on the cloud. Obtain a relevant ModelPath representing the document from:

ModelPathUtils.ConvertCloudGUIDsToCloudPath(Guid, Guid)

 

You need the BIM360 GUID to the project/file, see: ConvertCloudGUIDsToCloudPath 

 

0 Likes
Message 5 of 16

LucasJonnedeJong
Enthusiast
Enthusiast

Thanks @TripleM-Dev.net but ConvertCloudGUIDsToCloudPath is not the answer.  I tried it, and it gave me the CloudPath, which basically only confirmed to me that the CloudPath I had was the right one.  Thanks though.

0 Likes
Message 6 of 16

TripleM-Dev.net
Advisor
Advisor

@LucasJonnedeJong wrote:

Thanks @TripleM-Dev.net but ConvertCloudGUIDsToCloudPath is not the answer.  I tried it, and it gave me the CloudPath, 


So you've tried it, this means you already know the project GUID and model GUID?, use those!

 

I did some tests:

A. The Modelpath created from "BIM 360://..../....rvt -> this doesn't create a valid/usable cloudpath.

B. The Modelpath created from the project and model GUID does (see below)

ModelPathUtils.ConvertCloudGUIDsToCloudPath(projectguid, modelguid)

 C. The overloaded method with 'IOpenFromCloudCallback' doesn't seem to be required (would advise it so callbacks can be handled!)

D. Tested on a Revit 2019 WORKSHARED BIM 360 cloud model. for the methods "OpenAndActivateDocument" and "OpenDocumentFile"

 

See post below for use of the 'IOpenFromCloudCallback':

https://forums.autodesk.com/t5/revit-api-forum/how-to-implement-iopenfromcloudcallback-interface/td-... 

0 Likes
Message 7 of 16

LucasJonnedeJong
Enthusiast
Enthusiast

Hey @TripleM-Dev.net, thanks for sticking with me.  But I am afraid your suggestions are not the solution.  Like I said before:  I have used ConvertCloudGUIDsToCloudPath before, but all that did, was give me the ModelPath that I was already using.  And there is more evidence that I am using the correct ModelPath:  When I use ModelPath.CloudPath, it returns "true" and when I supply a wrong filelocation, Revit throws a different exception.   

Is there anything else you can think of that I can try?

 

Mr. @jeremytammik , I have seen a lot of solutions from you in this forum, anythin you can think of that I can try? 

Thanks, 

0 Likes
Message 8 of 16

TripleM-Dev.net
Advisor
Advisor

Hi,

 

That's true, I also tried setting "BIM 360:// etc///" and the ModelPath returns true for ModelPath.CloudPath

But the ModelGuid and ProjectGuid are empty.. (So the return of CloudPath is misleading).

 

Is the Model on BIM 360 a Workshared model or a non-workshared one and correct revit version.

maybe that's the issue?

 

I've tried the methods in my previous post and I can confirm it opens the workshared model.

Only difference maybe is Revit 2019 vs Revit 2020 API difference...unfortunately I don't have a 2020 project in BIM360 for testing.

 

- Michel

0 Likes
Message 9 of 16

jeremytammik
Autodesk
Autodesk

I seem to remember some internal discussion about that being work in progress.

 

Here is a public discussion of the same topic from last year:

 

https://stackoverflow.com/questions/51370445/how-to-get-project-guid-and-model-guid-from-pathname

 

Things are moving so fast with cloud access, it may well have changed already by now.

  



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 10 of 16

jeremytammik
Autodesk
Autodesk

Here is another similar discussion on StackOverflow:

 

https://stackoverflow.com/questions/59570209/is-it-possible-to-load-new-cloud-bim-360-links-in-a-rev...

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 11 of 16

LucasJonnedeJong
Enthusiast
Enthusiast

Thanks @jeremytammik for the links, but I have seen those, and don't contain information that help me get any further. 

Thanks @TripleM-Dev.net , I have made some progress.  I was able to open a BIM 360 project using the ModelPath that was converted from the GUID's (and it does not need the IOpenFromCloudCallback)   That is something that I can work with. 

BUT:  I still need to find the GUID's first, which I know how to do, but Why can't I open a model using the Modelpath that is converted from the uservisiblepath?   Here, for fun, I tried this (By the way, I have switched to C#, as there is much more information on how to do it):

Guid modelguid = Guid.Parse("bbd7d324-889b-4bb2-aa14-c9a626a20eff");
Guid projectguid = Guid.Parse("2706cbb1-26c5-4406-8697-77aef497a08f");
ModelPath file1 = ModelPathUtils.ConvertCloudGUIDsToCloudPath(projectguid, modelguid);
string fileloc = ModelPathUtils.ConvertModelPathToUserVisiblePath(file1);
ModelPath file = ModelPathUtils.ConvertUserVisiblePathToModelPath(fileloc);

OpenOptions openoptions = new OpenOptions();
openoptions.DetachFromCentralOption = DetachFromCentralOption.DoNotDetach;
openoptions.AllowOpeningLocalByWrongUser = false;
Document doc = app.OpenDocumentFile(file, openoptions);

And guess what?  I get the same exception.  It does not work.  

 

Let me summarize what I did, to make it better graspable:

  1. I get the modelpath (file1) from the GUID's. 
  2. When I open the model with this modelpath, it works fine.
  3. Then I convert the modelpath into a uservisiblepath, 
  4. then convert it back into a modelpath (file)
  5. When I open the model with this modelpath, it DOES NOT work.  Revit Throws an exception.  

Isn't that weird?   By now I am thinking it must be a bug....

 

Any ideas left?  Thanks!

0 Likes
Message 12 of 16

jeremytammik
Autodesk
Autodesk

I think you are right: it does not work.

 

I do not think it is a bug, but WIP.

 

Look at the notes from the recent Revit API roundtable meeting:

 

https://thebuildingcoder.typepad.com/blog/2020/11/revit-api-roundtable-notes.html

 

A Use design automation and the standard Revit API... Re v4: there is no need for a new version for this; we are already considering support for Dynamo scripting and access to cloud models and BIM360 docs.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 13 of 16

TripleM-Dev.net
Advisor
Advisor

Well I agree @LucasJonnedeJong  or actually I hope it's a Bug and not by design that you (always) need to have the GUIDs before.

 

Often links break because a new model (outside BIM360 source files) causes the GUID to change, while it's location and name on BIM360 stayed thesame. Having the modelpath to be able to be build from the BIM360 path and not GUID's would be a huge help.

 

In Revit they could have a function "Reload links based on name/location" would be nice 😊

 

- Michel

 

0 Likes
Message 14 of 16

LucasJonnedeJong
Enthusiast
Enthusiast

Hey guys @jeremytammik & @TripleM-Dev.net , thanks for your help.  I am a little bit confused:  if the 

 

ModelPathUtils.ConvertUserVisiblePathToModelPath(fileloc);

 

does not work for opening cloud models, then what is it for?  I am hoping that it will be made to work soon, so I can make the necessary user input more straight forward.  But at least I can stop looking for a solution for now.  

last question:  Where do I sign up to receive a notification when new Revit API is available?

 

Thanks again!

0 Likes
Message 15 of 16

TripleM-Dev.net
Advisor
Advisor

For opening non-cloud models with worksharing options....

 

Also I noticed this in the description of: OpenAndActivateDocument  (R2019 and up):

 

OpenAndActivateDocument(String)
Opens and activates a Revit document, include both local document or cloud document. (Inherited from UIApplication .)

 

This isn't the "OpenDocumentFile" but maybe "OpenAndActivateDocument" with the direct path to the BIM 360 works? Haven't tried it....

0 Likes
Message 16 of 16

LucasJonnedeJong
Enthusiast
Enthusiast

I have tried it, same exception thrown....   But yeah, you're right, the method does work for locally saved modelfiles with the modelpath converted from a string...

0 Likes