<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Save Model as Detached in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/save-model-as-detached/m-p/10232193#M26667</link>
    <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below the code I've compiled, but still getting the central model moved or copied message upon the opening of the model.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code supposed to work on the local model. So the workflow is as follows;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) find the central model&lt;/P&gt;&lt;P&gt;2) save the model to another folder temporarily&lt;/P&gt;&lt;P&gt;3) open temp central model detached&lt;/P&gt;&lt;P&gt;4) save the detached model to upload the folder&lt;/P&gt;&lt;P&gt;5) close the opened temp model&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Am I missing something? Any help is much appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;// 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;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 12 Apr 2021 18:27:01 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2021-04-12T18:27:01Z</dc:date>
    <item>
      <title>Save Model as Detached</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/save-model-as-detached/m-p/10232193#M26667</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below the code I've compiled, but still getting the central model moved or copied message upon the opening of the model.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code supposed to work on the local model. So the workflow is as follows;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) find the central model&lt;/P&gt;&lt;P&gt;2) save the model to another folder temporarily&lt;/P&gt;&lt;P&gt;3) open temp central model detached&lt;/P&gt;&lt;P&gt;4) save the detached model to upload the folder&lt;/P&gt;&lt;P&gt;5) close the opened temp model&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Am I missing something? Any help is much appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;// 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;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Apr 2021 18:27:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/save-model-as-detached/m-p/10232193#M26667</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-04-12T18:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: Save Model as Detached</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/save-model-as-detached/m-p/10232730#M26668</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unless you discard the worksets, which you don't really want to do.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Apr 2021 22:38:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/save-model-as-detached/m-p/10232730#M26668</guid>
      <dc:creator>RPTHOMAS108</dc:creator>
      <dc:date>2021-04-12T22:38:17Z</dc:date>
    </item>
  </channel>
</rss>

