Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding
Announcements
We are currently migrating data within this board to improve the community. During this process, posting, replying, editing and other features are temporarily disabled. We sincerely apologize for any inconvenience caused and appreciate your understanding. Thank you for your patience and support.

Finding user line styles

Kevin.Bell
Advisor Advisor
449 Views
4 Replies
Message 1 of 5

Finding user line styles

Kevin.Bell
Advisor
Advisor

I’m writing an addon that changes all the line styles of Detail Lines, Model Lines and the boarders of Filled Regions to a certain line style. But I'm having issues with distinguishing user built line styles from system / inbuilt ones.


To get all the lines styles and including the user and system ones, I use a FilteredElementCollector to find class GraphicsStyle:

 

IList<Element> getgs = new FilteredElementCollector(doc).OfClass(typeof(GraphicsStyle)).ToElements();



This works but returns a lot of styles some unrelated to lines, but I can use the GraphicStyleCategory then Parent then Name to find styles with the parent name “Lines”:

 

if (mystyle.GraphicsStyleCategory.Parent.Name == "Lines")

 

So now I have all the line styles, but I want to remove the system ones, which I thought were lines styles within < and >, such as <Thin Lines> or <Wide Lines>.

 

But, looking at the names that are returned, some have <>, some have only a > at the end and others don't have anything to distinguish them. These are the names returned:

 

<Room Separation>
<Insulation Batting Lines>
<Sketch>
<Lines>
<Thin Lines>
<Medium Lines>
<Wide Lines>
<Overhead>
<Hidden>
<Demolished>
<Beyond>
Boundary>
Riser>
Run>
Landing Center>
<Area Boundary>
<Hidden Lines>
<Space Separation>
<Lines>
<Lines>
<Lines>
Stair Path>
<Fabric Envelope>
<Fabric Sheets>
Railing Rail Path Lines
Railing Rail Path Extension Lines
<Centerline>
<Axis of Rotation>
<Path of Travel Lines>
<Load Area Separation>
MyStyle

 

Seems a little inconsistent to me... Is there any good way to pick out the 'system' line styles so that I can only find ones the user has created?

 

Cheers!

Reply
Reply
0 Likes
Accepted solutions (2)
450 Views
4 Replies
Replies (4)
Message 2 of 5

jeremy_tammik
Autodesk
Autodesk

One possible approach that might work is to look at their element ids. These objects are elements, stored in the BIM db, hence equipped with element ids, aren't they? The element ids are assigned one by one as things get added to the database. Hence, higher element ids are added later. They are also incremented consecutively as work progresses. While this behaviour is undocumented and not officially supported or guaranteed in any way whatsoever, it has been working like that forever, afaik. Therefore, if you determine the highest element id in your project right now, you know that everything with a higher id has been added later. Therefore, you know that all line styles with an id higher than the highest one when you started initial work on your BIM are user generated in one way or another, and all lower ones are built-in. Does this help?

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Reply
Reply
0 Likes
Message 3 of 5

Kevin.Bell
Advisor
Advisor
Accepted solution

Thanks for your response.

 

I think I've found another way which better does what I'm doing for. After reading more I found that I can collect all CurveElements from the project with this:

 

            List<CurveElement> AllCurves = new List<CurveElement>(new FilteredElementCollector(doc).OfClass(typeof(CurveElement)).ToElements().Cast<CurveElement>());

 

Iterate through them and use the method GetLineStyleIds() to get the GraphicsStyles... luckly these appear to be named correctly with <> denoting 'System' line styles.

 

Thanks.

 

Reply
Reply
0 Likes
Message 4 of 5

FAIR59
Advisor
Advisor
Accepted solution

A category has the property BuiltInCategory. The graphicalStyleCategory of a user-defined line has a value of BuiltIncategory.Invalid

            StringBuilder sb = new StringBuilder();
            Category LinesCat = Category.GetCategory(doc,BuiltInCategory.OST_Lines);
            IEnumerable<GraphicsStyle> getgs = new FilteredElementCollector(doc).OfClass(typeof(GraphicsStyle)).Cast<GraphicsStyle>();
            foreach(GraphicsStyle gs in getgs)
            {
            	Category cat = gs.GraphicsStyleCategory;
            	if(cat==null || cat.Parent==null) continue;
            	if(cat.Parent.Id.IntegerValue != LinesCat.Id.IntegerValue) continue;
            	if(cat.BuiltInCategory == BuiltInCategory.INVALID)
            	{
            		sb.AppendLine(string.Format("User defined Line: {0}",cat.Name));
            	} else
            	{
            		sb.AppendLine(string.Format("System defined Line {0} / {1}",cat.BuiltInCategory, cat.Name));
            	}
            }
            TaskDialog.Show("debug",sb.ToString());

 

Reply
Reply
Message 5 of 5

Kevin.Bell
Advisor
Advisor

Excellent, I can check for that too. Thanks.

Reply
Reply
0 Likes