Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Line Styles in use?

1 REPLY 1
Reply
Message 1 of 2
kevin_fielding
974 Views, 1 Reply

Line Styles in use?

kevin_fielding
Advocate
Advocate

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

 

0 Likes

Line Styles in use?

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

 

1 REPLY 1
Message 2 of 2

jeremytammik
Autodesk
Autodesk

Dear Kevin,

 

Thank you for your query.

 

This fits in well with my ongoing collection of snippets of purging functionality:

 

http://thebuildingcoder.typepad.com/blog/2017/04/forgefader-ui-lookup-builds-purge-and-room-instance...

 

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:

 

https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/BuildingCoder/C...

 

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



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes

Dear Kevin,

 

Thank you for your query.

 

This fits in well with my ongoing collection of snippets of purging functionality:

 

http://thebuildingcoder.typepad.com/blog/2017/04/forgefader-ui-lookup-builds-purge-and-room-instance...

 

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:

 

https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/BuildingCoder/C...

 

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



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report