Skip to content

Commit

Permalink
fix workset issue
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Nov 20, 2024
1 parent d1d01c7 commit 575fd57
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions Test/Sample/BenchmarkCommand/CategoriesCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ 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<Workset> worksets = fwc.WherePasses(wf).ToWorksets();
foreach (IGrouping<string, Element>? category in categories)
{
var categoryBenchmark = new CategoryBenchmark();
categoryBenchmark.ModelName = doc.Title + ".rvt";
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());
Expand All @@ -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<Element> elements)
public double CountWorksetName(ICollection<Workset> worksets,List<Element> elements)
{
List<string> names = new List<string>();
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();
}
Expand Down

0 comments on commit 575fd57

Please sign in to comment.