Skip to content

Commit

Permalink
Update script.py
Browse files Browse the repository at this point in the history
'Reset All Colors' button wouldn't work in Revit (colors remained).  This updates the resetColors class to make the action work.
  • Loading branch information
utilitas-firmitas authored Dec 9, 2024
1 parent dd1666e commit 61afd12
Showing 1 changed file with 41 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,27 +155,27 @@ def Execute(self, uiapp):
def GetName(self):
return "Set colors to elements"

class resetColors(IExternalEventHandler):
class ResetColors(UI.IExternalEventHandler):
def __init__(self):
pass

def Execute(self, uiapp):
try:
new_doc = uiapp.ActiveUIDocument.Document
view = getActiveView(new_doc)
if view != 0:
ogs = OverrideGraphicSettings().Dispose()
ogs = OverrideGraphicSettings()
collector = FilteredElementCollector(new_doc, view.Id).WhereElementIsNotElementType().WhereElementIsViewIndependent().ToElementIds()
t = Transaction(new_doc, "Reset colors in elements")
t.Start()
try:
#Get and ResetView Filters
new_doc = revit.DOCS.doc
view = get_active_view(new_doc)

if view == 0:
return

# First remove any existing filters
filters = view.GetFilters()
if filters and len(filters) > 0:
# Only remove filters for current category/parameter if selected
if hasattr(wndw, '_categories') and wndw._categories.SelectedIndex > 0:
sel_cat = wndw._categories.SelectedItem['Value']
sel_par = wndw._listBox1.SelectedItem['Value']
filter_name = sel_cat._name + "/"
filters = view.GetFilters()
if len(filters) != 0:

with revit.Transaction(doc=new_doc, name="Remove View Filters"):
for filt_id in filters:
filt_ele = new_doc.GetElement(filt_id)
if filt_ele.Name.StartsWith(filter_name):
Expand All @@ -184,15 +184,33 @@ def Execute(self, uiapp):
new_doc.Delete(filt_id)
except:
pass
except Exception as e:
pass
#Reset visibility
for id in collector:
view.SetElementOverrides(id, ogs)
t.Commit()
except Exception as e:
pass

# Then reset element overrides
with revit.Transaction(doc=new_doc, name="Reset Element Colors"):
# Create empty override settings
ogs = DB.OverrideGraphicSettings()

# Get all visible elements in view
collector = (DB.FilteredElementCollector(new_doc, view.Id)
.WhereElementIsNotElementType()
.WhereElementIsViewIndependent()
.ToElements())

# Reset overrides for elements
for element in collector:
if element.Category is not None:
# If category selected, only reset those elements
if hasattr(wndw, '_categories') and wndw._categories.SelectedIndex > 0:
sel_cat = wndw._categories.SelectedItem['Value']
if element.Category.Id.IntegerValue == sel_cat._cat.Id.IntegerValue:
view.SetElementOverrides(element.Id, ogs)
else:
# Reset all elements if no category selected
view.SetElementOverrides(element.Id, ogs)

except Exception as ex:
print("Error resetting colors: {}".format(ex))

def GetName(self):
return "Reset colors in elements"

Expand Down

0 comments on commit 61afd12

Please sign in to comment.