Skip to content

Instantly share code, notes, and snippets.

@chuongmep
Created December 29, 2023 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuongmep/87dfd1e1542aba07b02cce5ddce10214 to your computer and use it in GitHub Desktop.
Save chuongmep/87dfd1e1542aba07b02cce5ddce10214 to your computer and use it in GitHub Desktop.
public override void Action()
{
// get all forgetypeUnit
IList<ForgeTypeId> forgeTypeIds = UnitUtils.GetAllUnits();
List<UnitsData> UnitDict = new List<UnitsData>();
foreach (var forgeTypeId in forgeTypeIds)
{
// get label symbol
var symbol = FormatOptions
.GetValidSymbols(forgeTypeId).FirstOrDefault(x => x.Empty() == false);
if (symbol != null)
{
string labelForSymbol = LabelUtils.GetLabelForSymbol(symbol);
// pattent to split version and string :
// e.g : autodesk.unit.unit:britishThermalUnits-1.0.1 => autodesk.unit.unit:britishThermalUnits-1.0.1 and 1.0.1
var pattern = @"(.*)(-)(.*)";
var match = Regex.Match(forgeTypeId.TypeId, pattern);
UnitsData unitsData = new UnitsData();
unitsData.UnitLabel = labelForSymbol;
unitsData.TypeId = match.Groups[1].Value;
unitsData.Version = match.Groups[3].Value;
UnitDict.Add(unitsData);
}
}
// save to txt and open
string path = Path.Combine(Path.GetTempPath(), "units.json");
// save list object to json
string json = JsonConvert.SerializeObject(UnitDict, Formatting.Indented);
File.WriteAllText(path, json, Encoding.UTF8);
Process.Start(path);
}
@chuongmep
Copy link
Author

chuongmep commented Dec 29, 2023

LINQPad7_bmu0kqDtnh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment