9 Jun 2020

Worksharing model support by Revit Design Automation

Default blog image

Follow @JohnOnSoftware

Opening a Revit worksharing model on Revit Design Automation engine is a frequently asked question, and this is not supported directly by Revit Design Automation engine before, you need to handle it with a little bit of extra code, there is a discussion on StackOverflow talking about bypassing the dialog box “Model has been transmitted from remote location”. Now comes the good news, it's supported out of box by Revit Design Automation, please check the change log HERE

Improved the default behavior for opening and saving models that have worksharing enabled, in order to preserve worksets on open, and support saving the model as a new central.

While the Revit Design Automation engine allows opening of workshared model, the file is opened in DA as detached from central with the worksets being preserved (detach-and-preserve-workset option). This means that while saving the file, you will need to use the worksharing settings to save the new file as central, here is sample code to demo how to save the workshared model:

ModelPath path = ModelPathUtils.ConvertUserVisiblePathToModelPath("result.rvt");
// If a worshared file is opened as a part of this addin then the new file will be 
// saved as central.
SaveAsOptions opts = new SaveAsOptions();
if (doc.IsWorkshared)
    opts.SetWorksharingOptions(new WorksharingSaveAsOptions { SaveAsCentral = true });
    WorksharingUtils.RelinquishOwnership(doc, new RelinquishOptions(true), new TransactWithCentralOptions());
doc.SaveAs(path, new SaveAsOptions());

For details, you can also check the DeleteElementsApp sample.

Good luck with Forge ;)  

Related Article