IN THIS SCRIPT, I AM TRYING TO APPLY OVERRIDE GRAPHICS COLOR BY SELECTING ELEMENTS, AND IT SOLVED,
BUT IN THIS SCRIPT I JUST SOLVED IT WITH APPLY RGB COLOR NUMBER NOT SELECT BY COLOR,
SO HOW CAN I APPLY OVERRRIDE GRAPHICS BY SELECTING COLOR?
from Autodesk.Revit.DB import *
from pyrevit import revit, DB
from pyrevit import forms, script
from System.Collections.Generic import List
from Autodesk.Revit.UI.Selection import *
#-------------------------------------------------------------
doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument
app = __revit__.Application
#---------------------------------------------------------------
# Class to show name of hatch pattern type in forms
class form_patt(forms.TemplateListItem):
@property
def name(self):
return self.item.Name
# Class to show name of line pattern type in forms
class form_ln_patt(forms.TemplateListItem):
@property
def name(self):
return self.item.Name
#-------------------------------------------------------------------------
# Get the fill pattern element for solid fill (if it exists)
fill_patterns = DB.FilteredElementCollector(doc).OfClass(DB.FillPatternElement)
fill_patt_choose = forms.SelectFromList.show([form_patt(i) for i in fill_patterns] ,title = "Select one fill pattern",multiselect=False)
# Get the fill pattern element for solid fill (if it exists)
line_patterns = DB.FilteredElementCollector(doc).OfClass(DB.LinePatternElement)
line_patt_choose = forms.SelectFromList.show([form_ln_patt(i) for i in line_patterns] ,title = "Select one line pattern",multiselect=False)
# if hatch pattern select none
if fill_patt_choose == None:
forms.alert("no pattern apply to element", title = "script cancelled")
script.exit()
# if line pattern select none
if line_patt_choose == None:
forms.alert("no line pattern apply to element", title = "script cancelled")
script.exit()
# pick elements
try:
ref_picked_objects = uidoc.Selection.PickObjects(ObjectType.Element)
except:
forms.alert("element selection none", title = "script cancelled")
script.exit()
# Empty ID list
elementIds = List[DB.ElementId]()
# apply color number for cut pattern
color_red = int(forms.ask_for_string(default='1',prompt='red color:',title='rgb color(cut pattern)'))
color_green = int(forms.ask_for_string(default='1',prompt='green color:',title='rgb color(cut pattern)'))
color_blue = int(forms.ask_for_string(default='1',prompt='blue color:',title='rgb color(cut pattern)'))
# Define the color you want to apply
color = DB.Color(color_red, color_green, color_blue) # Red color, you can change values as needed
#color = forms.select_swatch(title='Select Color Swatch', button_name='Select')
# apply color number for cut line
color_red = int(forms.ask_for_string(default='1',prompt='red color:',title='rgb color(cut line)'))
color_green = int(forms.ask_for_string(default='1',prompt='green color:',title='rgb color(cut line)'))
color_blue = int(forms.ask_for_string(default='1',prompt='blue color:',title='rgb color(cut line)'))
ln_color = DB.Color(color_red, color_green, color_blue)
ln_wt = int(forms.ask_for_string(default='1',prompt='cut line wt:',title='cut line wt'))
# Loop through the selected elements and apply color
with revit.Transaction("Colorize Elements"):
for elementId in ref_picked_objects:
id = elementId.ElementId
#element_id = doc.GetElement(id)
# Apply fill pattern and color
override = DB.OverrideGraphicSettings()
override.SetCutForegroundPatternId(fill_patt_choose.Id)
override.SetCutLinePatternId(line_patt_choose.Id)
override.SetCutForegroundPatternColor(color)
override.SetCutLineColor(ln_color)
override.SetCutLineWeight(ln_wt)
doc.ActiveView.SetElementOverrides(id, override)