How to copy Line Styles from one file to another?

How to copy Line Styles from one file to another?

dantartaglia8696
Advocate Advocate
2,560 Views
4 Replies
Message 1 of 5

How to copy Line Styles from one file to another?

dantartaglia8696
Advocate
Advocate

Hi,

 

I have the need to copy all the Line Styles from one model to another, I'm trying to get the element ids for each element I need to copy. I found this post on the Building Coder: http://thebuildingcoder.typepad.com/blog/2013/08/retrieving-all-available-line-styles.html it says, "create a filtered element collector retrieving all ElementType elements belonging to any one of them". I cannot seem to create a FilteredElementCollector() to do this. I'm not entirely sure this is the correct approach for my task. Any help is appreciated!

 

Thanks,

Dan

Accepted solutions (2)
2,561 Views
4 Replies
Replies (4)
Message 2 of 5

Aaron.Lu
Autodesk
Autodesk
LineStyles are not elements, so you can't filter them out.
Would you like to try GraphicsStyle?
you can use class filter and category fileter together. i.e. filter class GraphicsStyle and then make sure the categories of these elements are the subset of subcategories of category OST_Lines.


Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 3 of 5

dantartaglia8696
Advocate
Advocate
Accepted solution

Hi Aaron,

 

Thanks for the reply. The below worked for me but I want to see if there is a better filtering approach:

 

FilteredElementCollector oCollector = new FilteredElementCollector(oDocSource);

ICollection<Element> oElements = oCollector.OfClass(typeof(GraphicsStyle)).ToElements();

foreach (Element oElement in oElements)

{

GraphicsStyle oGraphicsStyle = oElement as GraphicsStyle;

if (oGraphicsStyle.GraphicsStyleCategory.Parent == null)

continue;

if (oGraphicsStyle.GraphicsStyleCategory.Parent.Name.Equals("Lines", StringComparison.CurrentCultureIgnoreCase))

oElementIDs.Add(oGraphicsStyle.Id);

}

 

...I tried the below filtering but no results came back:

 

FilteredElementCollector oCollector = new FilteredElementCollector(oDocSource);

ElementCategoryFilter oCategoryFilter = new ElementCategoryFilter(BuiltInCategory.OST_Lines);

oElementIDs = oCollector.OfClass(typeof(GraphicsStyle)).WherePasses(oCategoryFilter).ToElementIds();

 

Thanks,

Dan

 

0 Likes
Message 4 of 5

Aaron.Lu
Autodesk
Autodesk
Accepted solution
Your solution looks good.

one thing: you can use Category.Id rather than Category.Name to check category, so that it won't have localization problem, like this:

(BuiltInCategory)oGraphicsStyle.GraphicsStyleCategory.Parent.Id.IntegerValue == BuiltInCategory.OST_Lines


Aaron Lu
Developer Technical Services
Autodesk Developer Network
Message 5 of 5

dantartaglia8696
Advocate
Advocate

Hi Aaron,

 

Thanks for all you help!

 

Dan

0 Likes