Retrieving useable line style

Anonymous

Retrieving useable line style

Anonymous
Not applicable

I was trying to retrieve useable line style(shown in combobox when we draw model or detail line) as typed below

 

FilteredElementCollector collector = new FilteredElementCollector(doc).OfClass(typeof(GraphicsStyle)).WhereElementIsNotElementType();

 

this code return so many graphicsstyle element.

 

i want to filter useable line style when draw line.

0 Likes
Reply
Accepted solutions (1)
1,053 Views
4 Replies
Replies (4)

Anonymous
Not applicable

Hi,

 

After playing a bit with RevitLookup, I've found that you need to check the ParentCategory of the GraphicStyle. In you case it should be Lines.

2016-07-28_1858.png

 

Try the following code. I didn't check it myself, but should work:

            var styles = 
                new FilteredElementCollector(doc)
                .OfClass(typeof(GraphicsStyle))
                .WhereElementIsNotElementType()
                .ToElements()
                .Where(e=>e.Category!=null 
                    && e.Category.Parent!=null 
                    && e.Category.Parent.Id == new ElementId(BuiltInCategory.OST_Lines));

Thanks,

Victor.

0 Likes

Anonymous
Not applicable

i was trying to your code. but return 0 result.

 

i changed code.

 

Category => GraphicsStyleCategory 

 

var styles =
               new FilteredElementCollector(doc)
               .OfClass(typeof(GraphicsStyle))
               .WhereElementIsNotElementType()
               .ToElements().Cast<GraphicsStyle>().Where(e => e.GraphicsStyleCategory != null && e.GraphicsStyleCategory.Parent != null && e.GraphicsStyleCategory.Parent.Id.Equals(new ElementId(BuiltInCategory.OST_Lines))).ToList();

 

this code is working. but this result is not what is expected.

0 Likes

Anonymous
Not applicable
Accepted solution
0 Likes

Anonymous
Not applicable
That's wierd, I just executed your code and it shows me exactly what you need.
I tried in Revit 2016.

Anyway, i glad you've found the solution.