Line Styles in use?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I'm trying to collect a list of unused lines styles so I can purge them. I have developed the following code: -
Category linesCat = doc.Settings.Categories.get_Item("Lines");
IList<Category> categoryList = linesCat.SubCategories
.Cast<Category>()
.ToList();
// filter out built in line styles typically identifiable but < and > characters.
ICollection<Category> FilteredLineStyles = new List<Category>();
foreach (Category cat in categoryList)
{
if (!cat.Name.Contains("<") ||
!cat.Name.Equals("Hidden Lines") ||
!cat.Name.Equals("Axis of Rotation") ||
!cat.Name.Equals("Boundary") ||
!cat.Name.Equals("Insulation Batting Lines") ||
!cat.Name.Equals("Lines") ||
!cat.Name.Equals("Medium Lines") ||
!cat.Name.Equals("Wide Lines") ||
!cat.Name.Equals("Thin Lines")
)
{
FilteredLineStyles.Add(cat);
}
}
IList<CurveElement> lines = new FilteredElementCollector(doc)
.WhereElementIsNotElementType()
.OfCategory(BuiltInCategory.OST_Lines)
.WherePasses(new LogicalOrFilter(
new List<ElementFilter>
{
new CurveElementFilter(CurveElementType.ModelCurve),
new CurveElementFilter(CurveElementType.DetailCurve)
})).Cast<CurveElement>()
.ToList<CurveElement>();
ICollection<Category> UnusedLineStyles = new List<Category>();
foreach (Category cat in FilteredLineStyles)
{
if (lines.Where<CurveElement>(k => k.LineStyle.Name == cat.Name).Count() == 0)
{
UnusedLineStyles.Add(cat);
}
}
The code is fine is functional, however iterating through the list of categories and using Link to find lines with the same Line style is pretty slow. I'm essentially iterating all the lines within my project several hundred times, my test file has 280 linestyles and 21,000 lines. I'd be very greatful if someone could suggest a quicker method. Is there another method of getting all Line Styles that are not in use?
Regards,
Kevin