Skip to content

Commit

Permalink
re
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Nov 19, 2024
1 parent 7caedcf commit 0d80a73
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 5 deletions.
18 changes: 13 additions & 5 deletions Test/Sample/OpenModelFromCloud.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme
var records = csv.GetRecords<DataInput>().ToList();
dataInputs.AddRange(records);
}

}

string csvFamily = BrowsePath();
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -83,6 +89,7 @@ public void OpenLogFileAndWrite(string message)
}
}
}

public string BrowsePath()
{
var dialog = new OpenFileDialog();
Expand All @@ -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; }
Expand Down
72 changes: 72 additions & 0 deletions Test/Sample/OpenModelFromCloudSimple.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
3 changes: 3 additions & 0 deletions Test/Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,8 @@
<ItemGroup>
<ProjectReference Include="..\Test2\Test2.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Sample\data\" />
</ItemGroup>

</Project>

0 comments on commit 0d80a73

Please sign in to comment.