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
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
Dear Kevin,
Thank you for your query.
This fits in well with my ongoing collection of snippets of purging functionality:
Here are some other recent discussions on purging line styles, including yours:
Oh, much much better still:
The Building Coder samples already implements an external command for it, CmdPurgeLineStyles:
I hope this helps.
Please test that, fix it if you encounter any issues with it, submit a pull request for me to integrate the fixes, and let us all know how it ends up working out.
Oh dear, I notice that CmdPurgeLineStyles is not documented in any blog post.
Your feedback would give me a handy reason to do so.
Thank you!
Best regards,
Jeremy
Dear Kevin,
Thank you for your query.
This fits in well with my ongoing collection of snippets of purging functionality:
Here are some other recent discussions on purging line styles, including yours:
Oh, much much better still:
The Building Coder samples already implements an external command for it, CmdPurgeLineStyles:
I hope this helps.
Please test that, fix it if you encounter any issues with it, submit a pull request for me to integrate the fixes, and let us all know how it ends up working out.
Oh dear, I notice that CmdPurgeLineStyles is not documented in any blog post.
Your feedback would give me a handy reason to do so.
Thank you!
Best regards,
Jeremy
Can't find what you're looking for? Ask the community or share your knowledge.