diff --git a/Test/Sample/OpenModelFromCloud.cs b/Test/Sample/OpenModelFromCloud.cs index 3802d34..49a282f 100644 --- a/Test/Sample/OpenModelFromCloud.cs +++ b/Test/Sample/OpenModelFromCloud.cs @@ -31,7 +31,6 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme var records = csv.GetRecords().ToList(); dataInputs.AddRange(records); } - } string csvFamily = BrowsePath(); @@ -50,7 +49,14 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme UpdateUFCodeBaseFamily updateUfCodeBaseFamily = new UpdateUFCodeBaseFamily(); updateUfCodeBaseFamily.Execute(document, csvFamily); // sync model - doc.SynchronizeWithCentral(new TransactWithCentralOptions(), new SynchronizeWithCentralOptions()); + 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; + doc.SynchronizeWithCentral(twcOpts, syncopt); OpenLogFileAndWrite("Sync model to central is done"); // close model doc.Close(false); @@ -62,9 +68,9 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme } return Result.Succeeded; - } - public void OpenLogFileAndWrite(string message) + + public void OpenLogFileAndWrite(string message) { string fileName = "log.txt"; string logFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), fileName); @@ -83,6 +89,7 @@ public void OpenLogFileAndWrite(string message) } } } + public string BrowsePath() { var dialog = new OpenFileDialog(); @@ -91,7 +98,8 @@ public string BrowsePath() dialog.ShowDialog(); return dialog.FileName; } - public class DataInput + + public class DataInput { public string item_id { get; set; } public string item_name { get; set; } diff --git a/Test/Sample/OpenModelFromCloudSimple.cs b/Test/Sample/OpenModelFromCloudSimple.cs new file mode 100644 index 0000000..d241c20 --- /dev/null +++ b/Test/Sample/OpenModelFromCloudSimple.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Net.Sockets; +using System.Windows; +using Autodesk.Revit.Attributes; +using Autodesk.Revit.DB; +using Autodesk.Revit.UI; +using CsvHelper; +using Microsoft.Win32; + +namespace Test; + +[Transaction(TransactionMode.Manual)] +public class OpenModelFromCloudSimple : IExternalCommand +{ + public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) + { + // open model from acc + var doc = commandData.Application.ActiveUIDocument.Document; + string region = "US"; + var projectGuid = new Guid("f10b5c85-fd34-435a-9206-e4a8c21d761c"); + var modelGuid = new Guid("119d11f3-4d92-4d50-81db-0a03aa20fd82"); + var modelPath = ModelPathUtils.ConvertCloudGUIDsToCloudPath(region, projectGuid, modelGuid); + // Document document = doc.Application.OpenDocumentFile(modelPath, new OpenOptions()); + // active document + commandData.Application.OpenAndActivateDocument(modelPath, new OpenOptions(), false); + // sync model + // close model + doc.Close(false); + + return Result.Succeeded; + + } + public void OpenLogFileAndWrite(string message) + { + string fileName = "log.txt"; + string logFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), fileName); + if (!File.Exists(logFile)) + { + using (StreamWriter sw = File.CreateText(logFile)) + { + sw.WriteLine(message); + } + } + else + { + using (StreamWriter sw = File.AppendText(logFile)) + { + sw.WriteLine(message); + } + } + } + public string BrowsePath() + { + var dialog = new OpenFileDialog(); + dialog.Filter = "Revit Files (*.csv)|*.csv"; + dialog.Title = "Select a items file"; + dialog.ShowDialog(); + return dialog.FileName; + } + public class DataInput + { + public string item_id { get; set; } + public string item_name { get; set; } + public string project_guid { get; set; } + public string model_guid { get; set; } + } +} \ No newline at end of file diff --git a/Test/Test.csproj b/Test/Test.csproj index 1d135b5..5c58d42 100644 --- a/Test/Test.csproj +++ b/Test/Test.csproj @@ -72,5 +72,8 @@ + + +