Message 1 of 2
Save Model as Detached
Not applicable
04-12-2021
11:27 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone,
I'm trying to save a detached version of a work-shared central model to a new folder to share out the model with other consultants so that while they are opening the model they will not encounter errors such as "central model moved or copied".
Below the code I've compiled, but still getting the central model moved or copied message upon the opening of the model.
The code supposed to work on the local model. So the workflow is as follows;
1) find the central model
2) save the model to another folder temporarily
3) open temp central model detached
4) save the detached model to upload the folder
5) close the opened temp model
Am I missing something? Any help is much appreciated.
// copy central model as dummy model to a tmp location
string centralFile = GetCentralModelFile(doc);
string centralName = System.IO.Path.GetFileNameWithoutExtension(centralFile);
string tmpDestFile = KnownFolders.GetPath(KnownFolder.Documents) + "\\" + centralName + "_tmp.rvt";
copyFile(centralFile, tmpDestFile);
// open tmp model as detached
OpenOptions opt = new OpenOptions();
opt.DetachFromCentralOption = DetachFromCentralOption.DetachAndPreserveWorksets;
ModelPath mp = ModelPathUtils.ConvertUserVisiblePathToModelPath(tmpDestFile);
uiapp.OpenAndActivateDocument(mp, opt, false);
// save model to upload path
SaveAsOptions options = new SaveAsOptions();
options.OverwriteExistingFile = true;
WorksharingSaveAsOptions worksharingSaveAsOptions = new WorksharingSaveAsOptions();
worksharingSaveAsOptions.SaveAsCentral = true;
options.SetWorksharingOptions(worksharingSaveAsOptions);
Document openedDoc = commandData.Application.ActiveUIDocument.Document;
string detachedUploadPath = @"Z:\_SIMBOL\07-BIM\UPLOAD\" + centralName + ".rvt";
openedDoc.SaveAs(detachedUploadPath, options);
////////////////////////////////
// close tmp model
UIApplication openedUiapp = commandData.Application.ActiveUIDocument.Application;
RevitCommandId closeDoc = RevitCommandId.LookupPostableCommandId(PostableCommand.Close);
openedUiapp.PostCommand(closeDoc);
private string GetCentralModelFile(Document doc)
{
var modelPath = doc.GetWorksharingCentralModelPath();
var centralServerPath = ModelPathUtils.ConvertModelPathToUserVisiblePath(modelPath);
return centralServerPath;
}