Color Splasher Improvements

A few months ago, we decided to translate from C# to Python the Revit Add-In, Color Splasher initially developed by BIM One, to include it in our set of tools.

We were very happy when we were contacted by @Jean-Marc to include this work in pyRevit toolbar. Jean Marc ported it to pyRevit and improved the tool by adding features like the creation of view filters.

We recently followed up on Jean´s work and wanted to leave some notes about potential improvements that we will soon publish in our tools and could also be included in pyRevit version:

-Reset button(External Event): Apart from overriding the graphics of the elements, detection and deletion of view filters and rules is included. I felt it was counterintuitive that the Reset button was not resetting the colours when View Filters were created.

sel_cat = wndw._categories.SelectedItem['Value']
sel_par = wndw._listBox1.SelectedItem['Value']
filter_name = sel_cat._name + "/"
filters = view.GetFilters()
if len(filters) != 0:
	for filt_id in filters:
		filt_ele = new_doc.GetElement(filt_id)
		if filt_ele.Name.StartsWith(filter_name):
			view.RemoveFilter(filt_id)
			try:
				new_doc.Delete(filt_id)
			except:
				pass

-Improvements in accuracy when creating view filters (External Event): The values passed to create the rules and filters were taken from the items in the UI. In some cases, creating view filters and applying colors was producing different results for the same set of elements with double parameters. We first stored the double values in the values_info class with:

self.values_double = []
if para.StorageType == StorageType.Double:
	self.values_double.Add(para.AsDouble())

When the creation of the filter was taking placed, those values were retrieved and the epsilon (accuracy) was defined based on those:

if param_storage_type == StorageType.Double:
	if item._value =="None" or len(item.values_double) == 0:
		equals_rule = ParameterFilterRuleFactory.CreateEqualsRule(parameter_id, "" , 0.001)
	else:
		minimo = min(item.values_double)
		maximo = max(item.values_double)
		avg_values = (maximo+minimo)/2
		equals_rule = ParameterFilterRuleFactory.CreateEqualsRule(parameter_id, avg_values, math.fabs(avg_values-minimo)+0.001)

-Non-BuiltInCategories Bug: As the filter of the elements and parameters is based on built in categories, object from non-builtincategories (such as CAD imports) were causing a bug. We excluded them in the getCategoriesAndParametersInUsed method by filtering out all categories that have a positive id value (non-buitincategories are the only with positive id value)

-Creation of filters: I felt it was counterintuitive that if you previously set some colors and then create the view filters, the colors in the elements in the view were not actually changing. Therefore, every time the button to create filters is pushed, the resetColors event is first called (cleaning elements overrides and previous view filters and rules) and then the new view filters are created and applied.

def Button6Click(self, sender, e):
	if self._listBox2.Items.Count > 0:
		self.reset_ev.Raise()
		self.filter_ev.Raise()

-The window was also made resizable and tested with different screen resolutions, so if you have long parameter values you can always enlarge it. This is a bit harded to include here as several anchor points were changed in different controls of the UI.

1 Like

Nice stuffs @Nonica.io
would you like to make the PR against the develop-4 branch with these improvements?

1 Like