Created
December 29, 2023 09:19
-
-
Save chuongmep/87dfd1e1542aba07b02cce5ddce10214 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
Author
chuongmep
commented
Dec 29, 2023
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment