Skip to content

Commit

Permalink
open and sync model
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Nov 19, 2024
1 parent e471cd7 commit 3ebe92e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
40 changes: 40 additions & 0 deletions Test/Sample/OpenModelAndSync.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.IO;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace Test;

[Transaction(TransactionMode.Manual)]
public class OpenModelAndSync : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
var doc = commandData.Application.ActiveUIDocument.Document;
string region = "US";
var projectGuid = new Guid("f10b5c85-fd34-435a-9206-e4a8c21d761c");
string input = @"D:\API\Revit\RevitAddInManager\Test\Sample\data\input.txt";
string guidModelInput = File.ReadAllText(input).Trim();
var modelGuid = new Guid(guidModelInput);
var modelPath = ModelPathUtils.ConvertCloudGUIDsToCloudPath(region, projectGuid, modelGuid);
// Document document = doc.Application.OpenDocumentFile(modelPath, new OpenOptions());
// active document
Document document = doc.Application.OpenDocumentFile(modelPath, new OpenOptions());
// reload latest
document.ReloadLatest(new ReloadLatestOptions() { });
// sync model
TransactWithCentralOptions twcOpts = new TransactWithCentralOptions();
SynchronizeWithCentralOptions syncopt = new SynchronizeWithCentralOptions();
RelinquishOptions rOptions = new RelinquishOptions(true);
rOptions.UserWorksets = true;
syncopt.SetRelinquishOptions(rOptions);
// syncopt.SaveLocalBefore = false;
// syncopt.SaveLocalAfter = false;
document.SynchronizeWithCentral(twcOpts, syncopt);
// publish model post command
// close model
document.Close(false);
return Result.Succeeded;
}
}
2 changes: 1 addition & 1 deletion Test/Sample/data/input.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a449f572-5520-448b-8ef8-ed9eee240694
9a6fb2f5-26e5-47a4-aa3f-587003c6e43b

0 comments on commit 3ebe92e

Please sign in to comment.