Skip to content

Commit 11097ff

Browse files
authored
Merge pull request #2904 from Isaiah-Narvaez-42/patch-5
Color Splash: implement search and refresh color overrides on paramet…
2 parents eb16048 + 0c581d5 commit 11097ff

File tree

2 files changed

+114
-26
lines changed

2 files changed

+114
-26
lines changed

extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/ColorSplasher.pushbutton/script.py

Lines changed: 114 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,32 @@ def Execute(self, uiapp):
127127
if not view:
128128
return
129129
solid_fill_id = solid_fill_pattern_id()
130+
131+
# Get current category and parameter selection
132+
sel_cat = wndw._categories.SelectedItem["Value"]
133+
if sel_cat == 0:
134+
return
135+
136+
# Find which parameter is currently checked
137+
checked_param = None
138+
for indx in range(wndw._list_box1.Items.Count):
139+
if wndw._list_box1.GetItemChecked(indx):
140+
checked_param = wndw._list_box1.Items[indx]["Value"]
141+
break
142+
143+
if checked_param is None:
144+
return
145+
146+
# Refresh element-to-value mappings to reflect current parameter values
147+
refreshed_values = get_range_values(sel_cat, checked_param, view)
148+
149+
# Create a mapping of value strings to user-selected colors
150+
color_map = {}
151+
for indx in range(wndw.list_box2.Items.Count):
152+
item = wndw.list_box2.Items[indx]["Value"]
153+
color_map[item.value] = (item.n1, item.n2, item.n3)
154+
130155
with revit.Transaction("Apply colors to elements"):
131-
sel_cat = wndw._categories.SelectedItem["Value"]
132156
get_elementid_value = get_elementid_value_func()
133157
if get_elementid_value(sel_cat.cat.Id) in (
134158
int(DB.BuiltInCategory.OST_Rooms),
@@ -137,7 +161,12 @@ def Execute(self, uiapp):
137161
):
138162
# In case of rooms, spaces and areas. Check Color scheme is applied and if not
139163
if version > 2021:
140-
if wndw.crt_view.GetColorFillSchemeId(sel_cat.cat.Id).ToString() == "-1":
164+
if (
165+
wndw.crt_view.GetColorFillSchemeId(
166+
sel_cat.cat.Id
167+
).ToString()
168+
== "-1"
169+
):
141170
color_schemes = (
142171
DB.FilteredElementCollector(new_doc)
143172
.OfClass(DB.ColorFillScheme)
@@ -156,21 +185,20 @@ def Execute(self, uiapp):
156185
else:
157186
wndw._txt_block5.Visible = False
158187

159-
for indx in range(wndw.list_box2.Items.Count):
160-
ogs = DB.OverrideGraphicSettings()
161-
color = DB.Color(
162-
wndw.list_box2.Items[indx]["Value"].n1,
163-
wndw.list_box2.Items[indx]["Value"].n2,
164-
wndw.list_box2.Items[indx]["Value"].n3,
165-
)
166-
ogs.SetProjectionLineColor(color)
167-
ogs.SetSurfaceForegroundPatternColor(color)
168-
ogs.SetCutForegroundPatternColor(color)
169-
if solid_fill_id is not None:
170-
ogs.SetSurfaceForegroundPatternId(solid_fill_id)
171-
ogs.SetCutForegroundPatternId(solid_fill_id)
172-
for idt in wndw.list_box2.Items[indx]["Value"].ele_id:
173-
view.SetElementOverrides(idt, ogs)
188+
# Apply colors using refreshed element IDs but preserved color choices
189+
for val_info in refreshed_values:
190+
if val_info.value in color_map:
191+
ogs = DB.OverrideGraphicSettings()
192+
r, g, b = color_map[val_info.value]
193+
color = DB.Color(r, g, b)
194+
ogs.SetProjectionLineColor(color)
195+
ogs.SetSurfaceForegroundPatternColor(color)
196+
ogs.SetCutForegroundPatternColor(color)
197+
if solid_fill_id is not None:
198+
ogs.SetSurfaceForegroundPatternId(solid_fill_id)
199+
ogs.SetCutForegroundPatternId(solid_fill_id)
200+
for idt in val_info.ele_id:
201+
view.SetElementOverrides(idt, ogs)
174202
except Exception:
175203
external_event_trace()
176204

@@ -665,6 +693,7 @@ def __init__(
665693
def InitializeComponent(self):
666694
self._spr_top = Forms.Label()
667695
self._categories = Forms.ComboBox()
696+
self._search_box = Forms.TextBox()
668697
self._list_box1 = Forms.CheckedListBox()
669698
self.list_box2 = Forms.ListBox()
670699
self._button_set_colors = Forms.Button()
@@ -678,8 +707,11 @@ def InitializeComponent(self):
678707
self._txt_block3 = Forms.Label()
679708
self._txt_block4 = Forms.Label()
680709
self._txt_block5 = Forms.Label()
710+
self._search_label = Forms.Label()
681711
self.tooltips = Forms.ToolTip()
682712
self.SuspendLayout()
713+
self._filtered_parameters = []
714+
self._all_parameters = []
683715
# Separator Top
684716
self._spr_top.Anchor = (
685717
Forms.AnchorStyles.Top | Forms.AnchorStyles.Left | Forms.AnchorStyles.Right
@@ -724,24 +756,43 @@ def InitializeComponent(self):
724756
self.tooltips.SetToolTip(
725757
self._txt_block3, "Select a parameter to color elements based on its value."
726758
)
759+
# Search Label
760+
self._search_label.Anchor = Forms.AnchorStyles.Top | Forms.AnchorStyles.Left
761+
self._search_label.Location = Drawing.Point(12, 77)
762+
self._search_label.Name = "searchLabel"
763+
self._search_label.Size = Drawing.Size(120, 16)
764+
self._search_label.Text = "Search:"
765+
self._search_label.Font = Drawing.Font(self.Font.FontFamily, 8)
766+
# Search TextBox
767+
self._search_box.Anchor = (
768+
Forms.AnchorStyles.Top | Forms.AnchorStyles.Left | Forms.AnchorStyles.Right
769+
)
770+
self._search_box.Location = Drawing.Point(12, 95)
771+
self._search_box.Name = "searchBox"
772+
self._search_box.Size = Drawing.Size(310, 20)
773+
self._search_box.Text = ""
774+
self._search_box.TextChanged += self.on_search_text_changed
775+
self.tooltips.SetToolTip(
776+
self._search_box, "Type to search and filter parameters."
777+
)
727778
# checkedListBox1
728779
self._list_box1.Anchor = (
729780
Forms.AnchorStyles.Top | Forms.AnchorStyles.Left | Forms.AnchorStyles.Right
730781
)
731782
self._list_box1.FormattingEnabled = True
732783
self._list_box1.CheckOnClick = True
733784
self._list_box1.HorizontalScrollbar = True
734-
self._list_box1.Location = Drawing.Point(12, 80)
785+
self._list_box1.Location = Drawing.Point(12, 122)
735786
self._list_box1.Name = "checkedListBox1"
736787
self._list_box1.DisplayMember = "Key"
737-
self._list_box1.Size = Drawing.Size(310, 158)
788+
self._list_box1.Size = Drawing.Size(310, 116)
738789
self._list_box1.ItemCheck += self.check_item
739790
self.tooltips.SetToolTip(
740791
self._list_box1, "Select a parameter to color elements based on its value."
741792
)
742793
# TextBlock4
743794
self._txt_block4.Anchor = Forms.AnchorStyles.Top | Forms.AnchorStyles.Left
744-
self._txt_block4.Location = Drawing.Point(12, 238)
795+
self._txt_block4.Location = Drawing.Point(12, 240)
745796
self._txt_block4.Name = "txtBlock4"
746797
self._txt_block4.Size = Drawing.Size(120, 23)
747798
self._txt_block4.Text = "Values:"
@@ -766,7 +817,7 @@ def InitializeComponent(self):
766817
)
767818
self.list_box2.FormattingEnabled = True
768819
self.list_box2.HorizontalScrollbar = True
769-
self.list_box2.Location = Drawing.Point(12, 262)
820+
self.list_box2.Location = Drawing.Point(12, 265)
770821
self.list_box2.Name = "listBox2"
771822
self.list_box2.DisplayMember = "Key"
772823
self.list_box2.DrawMode = Forms.DrawMode.OwnerDrawFixed
@@ -776,7 +827,7 @@ def InitializeComponent(self):
776827
)
777828
g = self.list_box2.CreateGraphics()
778829
self.list_box2.ItemHeight = int(g.MeasureString("Sample", self.new_fnt).Height)
779-
self.list_box2.Size = Drawing.Size(310, 280)
830+
self.list_box2.Size = Drawing.Size(310, 277)
780831
self.tooltips.SetToolTip(
781832
self.list_box2, "Reassign colors by clicking on their value."
782833
)
@@ -902,6 +953,8 @@ def InitializeComponent(self):
902953
self.Controls.Add(self._categories)
903954
self.Controls.Add(self._txt_block2)
904955
self.Controls.Add(self._txt_block3)
956+
self.Controls.Add(self._search_label)
957+
self.Controls.Add(self._search_box)
905958
self.Controls.Add(self._txt_block4)
906959
self.Controls.Add(self._txt_block5)
907960
self.Controls.Add(self._list_box1)
@@ -1015,6 +1068,7 @@ def list_selected_index_changed(self, sender, e):
10151068
clr_dlg.Color.R, clr_dlg.Color.G, clr_dlg.Color.B
10161069
)
10171070
self.list_box2.SelectedIndex = -1
1071+
self.list_box2.Refresh()
10181072

10191073
def colour_item(self, sender, e):
10201074
try:
@@ -1094,15 +1148,51 @@ def update_filter(self, sender, e):
10941148
names_par = [x.name for x in sel_cat.par]
10951149
for key_, value_ in zip(names_par, sel_cat.par):
10961150
self._table_data_2.Rows.Add(key_, value_)
1151+
self._all_parameters = [
1152+
(key_, value_) for key_, value_ in zip(names_par, sel_cat.par)
1153+
]
10971154
self._list_box1.DataSource = self._table_data_2
10981155
self._list_box1.DisplayMember = "Key"
1156+
self._search_box.Text = ""
10991157
for indx in range(self._list_box1.Items.Count):
11001158
self._list_box1.SetItemChecked(indx, False)
11011159
self.list_box2.DataSource = self._table_data_3
11021160
else:
1161+
self._all_parameters = []
11031162
self._list_box1.DataSource = self._table_data_2
11041163
self.list_box2.DataSource = self._table_data_3
11051164

1165+
def on_search_text_changed(self, sender, e):
1166+
"""Filter parameters based on search text"""
1167+
search_text = self._search_box.Text.lower()
1168+
1169+
# Create new filtered data table
1170+
filtered_table = DataTable("Data")
1171+
filtered_table.Columns.Add("Key", System.String)
1172+
filtered_table.Columns.Add("Value", System.Object)
1173+
1174+
# Filter parameters based on search text
1175+
if len(self._all_parameters) > 0:
1176+
for key_, value_ in self._all_parameters:
1177+
if search_text == "" or search_text in key_.lower():
1178+
filtered_table.Rows.Add(key_, value_)
1179+
1180+
# Store current checked state
1181+
checked_items = [
1182+
self._list_box1.Items[indx]["Value"]
1183+
for indx in self._list_box1.CheckedIndices
1184+
]
1185+
1186+
# Update data source
1187+
self._list_box1.DataSource = filtered_table
1188+
self._list_box1.DisplayMember = "Key"
1189+
1190+
# Restore checked state for items that are still visible
1191+
for indx in range(self._list_box1.Items.Count):
1192+
item_value = self._list_box1.Items[indx]["Value"]
1193+
if item_value in checked_items:
1194+
self._list_box1.SetItemChecked(indx, True)
1195+
11061196

11071197
class FormSaveLoadScheme(Forms.Form):
11081198
def __init__(self):
@@ -1489,12 +1579,10 @@ def get_used_categories_parameters(cat_exc, acti_view):
14891579
if par.Definition.BuiltInParameter not in (
14901580
DB.BuiltInParameter.ELEM_CATEGORY_PARAM,
14911581
DB.BuiltInParameter.ELEM_CATEGORY_PARAM_MT,
1492-
):
1582+
):
14931583
list_parameters.append(ParameterInfo(1, par))
14941584
# Sort and add
1495-
list_parameters = sorted(
1496-
list_parameters, key=lambda x: x.name.upper()
1497-
)
1585+
list_parameters = sorted(list_parameters, key=lambda x: x.name.upper())
14981586
list_cat.append(CategoryInfo(ele.Category, list_parameters))
14991587
list_cat = sorted(list_cat, key=lambda x: x.name)
15001588
return list_cat

release_notes.md

4.38 KB

Downloads

🔹 See Assets section below for all download options

pyRevit

pyRevit CLI (Command line utility)

git for-each-ref refs/tags/v* --sort=-creatordate --format=%(refname) --count=1 git log --pretty=format:%h %s%n%b%n/ v5.2.0.25181+1357..HEAD

Highlights

  • Resolved #2880: Enhancements for Measure 3D
  • Resolved #2881: proposed tool: sectionbox navigator
  • Implemented #2793: feat: Allow for an option to close other outputs for all scripts in pyrevit settings
  • Implemented #2274: Water and Airflow parameters - Sum total tool unit fix
  • Implemented #2847: linkify too long error message isn't descriptive

Changes

Tools

  • Improved #2864: feat: Print Sheets: DWG exporter, progress bar, crash prevention + more
  • Improved #2865: tool: Improved overall tool functionality - ViewRange
  • Resolved #2873: New tool simple xls ex+import
  • Improved #2866: refactor: View Range window layout and bindings
  • Resolved #2880: Enhancements for Measure 3D
  • Resolved #2881: proposed tool: sectionbox navigator
  • Resolved #2883: Add Relink Textures tool to pyRevitTools
  • Resolved #2877: Add clean option to bundle.yaml configuration
  • Improved #2827: Rewrite of the print_table function: module "output" init.py
  • Improved #2825: Enhancement for "Count Faces": Coarse+Fine
  • Resolved #2812: Update pyrevitlib\rpws\server.py

Runtime

  • Resolved #2879: Update binary files

Engines

  • Resolved #2877: Add clean option to bundle.yaml configuration

Bundles

  • Improved #1809: Content bundle _content requirement removal

Localization

  • Resolved #2850: Add Russian Localization

Extensions

  • Resolved #2824: Adding Revitesse to extensions

0 commit comments

Comments
 (0)