Managing Line Styles - Principle

Managing Line Styles - Principle

Kevin.Bell
Advisor Advisor
979 Views
8 Replies
Message 1 of 9

Managing Line Styles - Principle

Kevin.Bell
Advisor
Advisor

Hi All,

 

I'm looking to put together an add on that manages line styles within a project, I'm happy with the coding for this but am interested in getting thoughts from everyone on how this will work in principle.

 

So I'm looking to do the following:

 

1. User pick a line style to remove from the project.

2. Routine builds a FilteredElementCollector of the line class.

3. The routine iterates all lines and makes a list of lines which use the style to be removed (using the 'Line Style' parameter).

4. The routine iterates the list from item 3 above, swaps all lines to a new line style.

5. The routine then deletes the line style to be removed (as nothing should be using it (hopefully)).

 

So I'm happy with the above, but I'm unsure if I get a FilteredElementCollector of the line class whether I'll get all Elements within the project that are using the line style, for instance, I don't believe it will find lines that are being used in a filled region...

 

So any thoughts on the above, is there a better way of finding all objects that use the Line Style I want to remove?

 

Cheers,

0 Likes
980 Views
8 Replies
Replies (8)
Message 2 of 9

jeremytammik
Autodesk
Autodesk

The best way is probably to try it out.

 

Since you are interested only in lines using a specific style, you can add a parameter filter to your collector specifying that specific style. That will eliminate all other lines from the collector:

 

http://thebuildingcoder.typepad.com/blog/2017/06/finding-an-exit-path-and-elementid-parameter-values...

 

Also, you might want to try deleting the style first, and seeing whether the return value of the call to Delete includes all affected elements. If so, you could undo the deletion using the temporary transaction trick TTT, modify the elements returned, and then repeat the deletion. Hopefully, the second time around, doing the real thing, no additional elements will be affected.

 

Note the use of the `deletedIdSet` in the Delete method sample code:

 

https://apidocs.co/apps/revit/2019/f4ce9113-b164-954e-5025-7b4edbdcc07d.htm

 

So, you may not need a collector at all...  ?

 

Cheers,

 

Jeremy

 



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

Message 3 of 9

Kevin.Bell
Advisor
Advisor

Great - thanks for the tips, I'll give them a try and report back.

 

Cheers.

0 Likes
Message 4 of 9

Kevin.Bell
Advisor
Advisor

OK, tried to delete the line style and check the IDs of the deleted elements - unfortunately, this only returns the Id of the deleted line style, not any elements that have changed... So I can't use that.

 

I tried the FilteredElementCollector method:

 

            ParameterValueProvider paramvalueprov = new ParameterValueProvider(new ElementId((int)BuiltInParameter.BUILDING_CURVE_GSTYLE));

            FilterNumericRuleEvaluator filtrule = new FilterNumericEquals();

            FilterElementIdRule filterelementtest = new FilterElementIdRule(paramvalueprov, filtrule, alllineStylesId[21]);

            ElementParameterFilter efilter = new ElementParameterFilter(filterelementtest);

            FilteredElementCollector foundeles = new FilteredElementCollector(doc, doc.ActiveView.Id).WherePasses(efilter);

It look me a long time to work out that the Line Style was a Built in parameter called 'Building_Curve_Gstyle' - 🙂

 

So this method works, and returns lines using the Line Style I want to delete, but I've noticed that it doesn't find anything which uses the line style in its definition - i.e. a filled region, where the user changes one of the lines of the region to the style I want to delete.

 

I could search for filled regions and obtain their lines, but my concern is that there may be other 'objects' that use the line style that I've not thought of.

 

Really, I need some sort of method of searching the database for anything using the line style...

0 Likes
Message 5 of 9

jeremytammik
Autodesk
Autodesk

Congratulations on making good progress and thank you for sharing your results.

 

Well, I can think of a pretty simple approach that you could use to test searching the database for anything using the line style.

 

I would expect anything using the line style to store the line style element id in some parameter or other.

 

Therefore, you could collect all elements in the database and search all their parameters, ignoring all parameters that are not element id value type.

 

Collecting all elements can be achieved using a logical or of 'element type' and not element type': 

 

https://thebuildingcoder.typepad.com/blog/2010/06/filter-for-all-elements.html

 

To retrieve all parameters from an element, you might want to go down two separate paths: retrieve the 'official' parameters returned by its Parameters property:

 

https://apidocs.co/apps/revit/2019/7af5d66f-4533-33d2-dd82-d9573eaabf15.htm

 

Plus, iterate over all the built-in parameters enumeration values and attempt to retrieve a parameter from the element for each entry. That may yield some additional 'non-official' parameters on some elements. That is the approach used by the RevitLookup 'snoop parameters' function and the BipChecker:

 

https://github.com/jeremytammik/BipChecker

 

I'll be interested to hear your results.

 



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

Message 6 of 9

Kevin.Bell
Advisor
Advisor

But would not the problem with that approach be that I would have to iterate through pretty much the whole database to find which elements refer to the ID of the line style I'm looking for - and so this would be slow on a large project.

 

The issue that I've found is that I don't know the parameter name that I'm looking for, only the parameter value (as I've found lines use the BuiltInParameter.Building_Curve_Gstyle but fillted regions must use some other sort of parameter (I need to check).

 

I'm wondering if I could construct a ElementParameterFilter that finds anything with a parameter value of ElementId.The-graphic-style-I-want?

 

i.e. :

ParameterValueProvider paramvalueprov = new ParameterValueProvider(new 'Any ElementId parameter');

            FilterNumericRuleEvaluator filtrule = new FilterNumericEquals();

            FilterElementIdRule filterelementtest = new FilterElementIdRule(paramvalueprov, filtrule, ElementId.The-graphic-style-I-want);

            ElementParameterFilter efilter = new ElementParameterFilter(filterelementtest);

            FilteredElementCollector foundeles = new FilteredElementCollector(doc, doc.ActiveView.Id).WherePasses(efilter);

 

0 Likes
Message 7 of 9

jeremytammik
Autodesk
Autodesk

Problem: I am pretty sure the specific parameter that you are testing is fixed in the parameter filter.

 

So, you would need to create a new parameter filter for each and every possible element-id-valued parameter.

 



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

Message 8 of 9

FAIR59
Advisor
Advisor

if you use the "delete" method, you can subscribe to the DocumentChanged event, to get a List of Elements that have changed as a result of the deletion. These should include the sketchlines of regions.

0 Likes
Message 9 of 9

Kevin.Bell
Advisor
Advisor

@jeremytammik - Thanks, I'll do some more investigation. I'm wondering if its just easy to filter for Lines, Filled Regions and Masking Regions - I can't think of anything else that uses Line Styles (could be wrong though!)

 

@FAIR59 - Now that's an interesting approach, I've never done any Event programming before, I'll have to do some reading and try it out.

 

Thanks for your responses.

0 Likes