Save Model as Detached

Save Model as Detached

Anonymous
Not applicable
1,885 Views
1 Reply
Message 1 of 2

Save Model as Detached

Anonymous
Not applicable

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;
}

 

 

0 Likes
1,886 Views
1 Reply
Reply (1)
Message 2 of 2

RPTHOMAS108
Mentor
Mentor

I believe your issue is one you can't avoid i.e. wherever you save the detached model to will become the central location when that model is copied elsewhere from there. i.e. your upload folder will become stored central location.

 

Unless you discard the worksets, which you don't really want to do.

 

It is usually up to the people at other end to open detached again. Most don't bother as if they are only using as links they don't have to. It is annoying sometimes when you open the file of another consultant and you get worksharing issues related to setting a section box in a View3D etc. but opening detached is what they should be doing to avoid this.

0 Likes