From 575fd5764f81075f66dc49c68c09edf680d694ea Mon Sep 17 00:00:00 2001 From: chuongmep <31106432+chuongmep@users.noreply.github.com> Date: Wed, 20 Nov 2024 21:08:49 +0800 Subject: [PATCH] fix workset issue --- Test/Sample/BenchmarkCommand/CategoriesCommand.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Test/Sample/BenchmarkCommand/CategoriesCommand.cs b/Test/Sample/BenchmarkCommand/CategoriesCommand.cs index 3136ff4..3f3d9d9 100644 --- a/Test/Sample/BenchmarkCommand/CategoriesCommand.cs +++ b/Test/Sample/BenchmarkCommand/CategoriesCommand.cs @@ -20,6 +20,9 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme .WhereElementIsNotElementType() .Where(x=>x.Category!=null) .GroupBy(x => x.Category.Name); + FilteredWorksetCollector fwc = new FilteredWorksetCollector(doc); + WorksetKindFilter wf = new WorksetKindFilter(WorksetKind.UserWorkset); + ICollection worksets = fwc.WherePasses(wf).ToWorksets(); foreach (IGrouping? category in categories) { var categoryBenchmark = new CategoryBenchmark(); @@ -27,7 +30,7 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme categoryBenchmark.Count = category.Count(); categoryBenchmark.Id = category.First().Category.Id.ToString(); categoryBenchmark.Name = category.Key; - categoryBenchmark.Workset = CountWorksetName(doc,category.ToList()); + categoryBenchmark.Workset = CountWorksetName(worksets,category.ToList()); categoryBenchmark.Family = CountFamilyName(category.ToList()); categoryBenchmark.Type = CountFamilyTypeName(category.ToList()); categoryBenchmark.Nestest = CountNestestElement(category.ToList()); @@ -37,22 +40,22 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme categoryBenchmarks.Add(categoryBenchmark); } // save csv - string folderPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments); + string folderPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.UserProfile); string filePath = System.IO.Path.Combine(folderPath, "categories.csv"); CsvUtils.WriteCsvCategories(categoryBenchmarks, filePath); Process.Start(filePath); return Result.Succeeded; } - public double CountWorksetName(Document doc,List elements) + public double CountWorksetName(ICollection worksets,List elements) { List names = new List(); - WorksetTable worksetTable = doc.GetWorksetTable(); + // get user workset created foreach (Element element in elements) { WorksetId worksetId = element.WorksetId; if (worksetId == WorksetId.InvalidWorksetId) continue; - Workset workset = worksetTable.GetWorkset(worksetId); - names.Add(workset.Name); + var workset = worksets.FirstOrDefault(x => x.Id == worksetId); + if (workset != null) names.Add(workset.Name); } return names.Distinct().Count(); }