How to implement IOpenFromCloudCallback interface?

How to implement IOpenFromCloudCallback interface?

Anonymous
Not applicable
1,026 Views
3 Replies
Message 1 of 4

How to implement IOpenFromCloudCallback interface?

Anonymous
Not applicable

Hi everyone,

 

I am trying using Revit API 2019 to detach a model from BIM360 as following code: 

UIApplication app = commandData.Application; 
 string path = "BIM 360://myfile"; 
ModelPath modelPath = ModelPathUtils.ConvertUserVisiblePathToModelPath(path);
            OpenOptions openOptions = new OpenOptions();
            openOptions.DetachFromCentralOption = DetachFromCentralOption.DetachAndDiscardWorksets;

            using (Transaction t = new Transaction(document, "Open Cloud model"))
            {
                t.Start();
                app.OpenAndActivateDocument(modelPath, openOptions, true, IOpenFromCloudCallback);

                t.Commit();
            }

And my problem is I don't know how to implement IopenFromCloudCallback correctly so if anyone have experience with this, please help me. 

Thank you so much :).

 

Best Regards,

 

Cherry Truong

0 Likes
1,027 Views
3 Replies
Replies (3)
Message 2 of 4

jeremytammik
Autodesk
Autodesk

Dear Cherry,

 

As I just said in my answer to your comment on The Building Coder, I am checking with the development team to see whether they have a sample to share:

 

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

 

Best regards,

 

Jeremy

 



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

0 Likes
Message 3 of 4

Anonymous
Not applicable

Hi @jeremytammik ,

 

Thank you for your respond. I just figure out how to implement it by following code Smiley Very Happy

     public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {         
           
            // Get control of the current document 
            UIDocument uIDocument = commandData.Application.ActiveUIDocument;
            UIApplication app = commandData.Application; 
            // Get document control
            Document document = uIDocument.Document;

            // Get current active view
            Autodesk.Revit.DB.View currentview = document.ActiveView;

            Guid projectid = Guid.Parse("myProjectGUID");
            Guid modelid = Guid.Parse("myModelGUID");

            ModelPath modelPath = ModelPathUtils.ConvertCloudGUIDsToCloudPath(projectid, modelid);

             OpenOptions openOptions = new OpenOptions();
            IOpenFromCloudCallback openFromCloudCallback = new cloudinterdace();

            app.OpenAndActivateDocument(modelPath, openOptions, true, openFromCloudCallback);


            return Result.Succeeded;




        }

    }


    public class cloudinterdace : IOpenFromCloudCallback
    {
        public OpenConflictResult OnOpenConflict(OpenConflictScenario scenario)
        {
            throw new NotImplementedException();
        }
    }

Best Regards,

 

Cherry  Truong

0 Likes
Message 4 of 4

phil_xia
Autodesk
Autodesk

Hi @Anonymous , I am Phil from Revit engineering team. I saw your sample and the exception thrown in the implementation of IOpenFromCloudCallback probably not a good choice. You can use the default implementation provided by DefaultOpenFromCloudCallback class which will always use the latest for open conflict.

Here is the introduction for this callback in Revit API 2019 what's new -

>>

The callback method:

  • Autodesk.Revit.DB.IOpenFromCloudCallback.OnOpenConflict()

can be passed to the document open methods to gain to handle conflict cases.   The method is passed an OpenConflictScenario value identifying the reason for the conflict ( Rollback, Relinquished or OutOfDate) and should return an OpenConflictResult with the desired response (keep local changes, discard local changes and open the latest version or cancel).

The new class:

  • DefaultOpenFromCloudCallback

provides a default way to handle conflicts: it always discards the local change and gets the latest version from the cloud.

<<

I list the corresponding UI for the input OpenConflictScenario for your reference and you can implement your handling logic to return KeepLocalChanges, DiscardLocalChangesAndOpenLatestVersion or just cancel the opening.

 

  • OpenConflictScenario.OutOfDate

 

  • OpenConflictScenario.Rollback

 

  • OpenConflictScenario.Relinquished

0 Likes