def prepare_colors(groups_dict): """Prepare a list of vg overrides for each group type""" groups_colors = {} count = sum( [len(groups) for groups in groups_dict.values() if len(groups) > 1]) colors = [DB.Color(x[0], x[1], x[2]) for x in generate_colors(count)] color_gray = DB.Color(128, 128, 128) j = 0 for gt_id in groups_dict.keys(): if len(groups_dict[gt_id]) == 1: color = color_gray else: color = colors[j] j += 1 if HOST_APP.is_newer_than(2019, or_equal=True): groups_colors[gt_id] = ( DB.OverrideGraphicSettings().SetProjectionLineColor(color). SetProjectionLineWeight(6).SetSurfaceBackgroundPatternColor( color).SetCutLineColor(color).SetCutLineWeight( 6).SetCutBackgroundPatternColor(color)) else: groups_colors[gt_id] = (DB.OverrideGraphicSettings( ).SetProjectionLineColor(color).SetProjectionLineWeight( 6).SetProjectionFillColor(color).SetCutLineColor( color).SetCutLineWeight(6).SetCutFillColor(color)) return groups_colors
def colorvg(r, g, b, projline_only=False, xacn_name=None): color = DB.Color(r, g, b) wireframe_color = DB.Color(r - 20 if r - 20 >= 0 else 0, g - 20 if g - 20 >= 0 else 0, b - 20 if b - 20 >= 0 else 0) with revit.Transaction(xacn_name or 'Set Color VG override'): for el in selection: if isinstance(el, DB.Group): for mem in el.GetMemberIds(): selection.append(revit.doc.GetElement(mem)) ogs = DB.OverrideGraphicSettings() ogs.SetProjectionLineColor(wireframe_color) ogs.SetCutLineColor(wireframe_color) if not projline_only: if HOST_APP.is_newer_than(2018): ogs.SetSurfaceForegroundPatternColor(color) ogs.SetCutForegroundPatternColor(color) else: ogs.SetProjectionFillColor(color) ogs.SetCutFillColor(color) solid_fpattern = find_solid_fillpat() if solid_fpattern: if HOST_APP.is_newer_than(2018): ogs.SetCutForegroundPatternId(solid_fpattern.Id) ogs.SetSurfaceForegroundPatternId(solid_fpattern.Id) else: ogs.SetProjectionFillPatternId(solid_fpattern.Id) ogs.SetCutFillPatternId(solid_fpattern.Id) else: logger.warning('Can not find solid fill pattern in model' 'to assign as projection/cut pattern.') revit.doc.ActiveView.SetElementOverrides(el.Id, ogs)
def reformat_colour(col_sting): # reformat strings representing colour and create elements of type DB.Color new_col = col_sting.replace("-", " ") rgb_str = new_col.split() r = int(rgb_str[0]) g = int(rgb_str[1]) b = int(rgb_str[2]) return DB.Color(r, g, b)
def SetElementColor(R, G, B, A): color = DB.Color(R,G,B) ogs = DB.OverrideGraphicSettings() ogs.SetProjectionLineColor(color) ogs.SetSurfaceBackgroundPatternColor(color) ogs.SetCutForegroundPatternColor(color) ogs.SetCutBackgroundPatternColor(color) ogs.SetCutLineColor(color) ogs.SetSurfaceForegroundPatternColor(color) ogs.SetSurfaceTransparency(A) return ogs
def prepare_colors(groups_dict): groups_colors = {} count_1 = 0 count_n = 0 for k in groups_dict.keys(): if len(groups_dict[k]) == 1: # one instance of a group count_1 += 1 else: # several instances count_n += 1 colors_all = colors(count_1 + count_n) _colors_1 = [blend_color(x) for x in colors_all[:count_1]] _colors_n = colors_all[count_1:] colors_1 = [DB.Color(x[0], x[1], x[2]) for x in _colors_1] colors_n = [DB.Color(x[0], x[1], x[2]) for x in _colors_n] i = 0 j = 0 for k in groups_dict.keys(): if len(groups_dict[k]) == 1: logger.debug("len(groups_dict[k]) == 1") color = colors_1[i] i += 1 else: color = colors_n[j] j += 1 groups_colors[k] = \ DB.OverrideGraphicSettings() \ .SetProjectionLineColor(color) \ .SetProjectionLineWeight(6) \ .SetCutLineColor(color) \ .SetCutLineWeight(6) \ .SetCutFillColor(color) \ .SetProjectionFillColor(color) return groups_colors
def colorvg(r, g, b, projline_only=False, xacn_name=None): color = DB.Color(r, g, b) with revit.Transaction(xacn_name or 'Set Color VG override'): for el in selection: if isinstance(el, DB.Group): for mem in el.GetMemberIds(): selection.append(revit.doc.GetElement(mem)) ogs = DB.OverrideGraphicSettings() ogs.SetProjectionLineColor(color) if not projline_only: ogs.SetProjectionFillColor(color) solid_fpattern = find_solid_fillpat() if solid_fpattern: ogs.SetProjectionFillPatternId(solid_fpattern.Id) else: logger.warning('Can not find solid fill pattern in model' 'to assign as projection pattern.') revit.doc.ActiveView.SetElementOverrides(el.Id, ogs)
import Autodesk.Revit.DB as DB app = __revit__.Application # not used ---------------------------------- #doc = __revit__.ActiveUIDocument.Document #uidoc = __revit__.ActiveUIDocument #app = UIApplication.Application # -------------------------------------------- #----------SETUP COLORS FOR CHECKING---------- check_black = [] check_white = [] bg_check = [] color_black = DB.Color(0, 0, 0) color_white = DB.Color(255, 255, 255) check_black.append(color_black.Red) check_black.append(color_black.Green) check_black.append(color_black.Blue) check_white.append(color_white.Red) check_white.append(color_white.Green) check_white.append(color_white.Blue) #--------------------------------------------- #bg_col = app.BackgroundColor # #bg_check.append(bg_col.Red) #bg_check.append(bg_col.Green) #bg_check.append(bg_col.Blue)
"""Generate FilledRegion Swatches""" #pylint: disable=E0401,C0103 from pyrevit import revit, DB fillpats = revit.query.get_types_by_class(DB.FillPatternElement) with revit.Transaction('Generate FilledRegion Types'): for fillpat in fillpats: if fillpat.Name.startswith('#'): print(fillpat.Name) filledregion_type = \ revit.create.create_filledregion(fillpat.Name, fillpat) filledregion_type.ForegroundPatternColor = DB.Color(128, 128, 128) filledregion_type.LineWeight = 1 filledregion_type.IsMasking = True
subNames = [] if subCats: for sub in subCats: if sub.Name == "Named References": named_subcat_id = sub.Id elif sub.Name == "Weak References": weak_subcat_id = sub.Id elif sub.Name == "Not References": not_subcat_id = sub.Id subNames.append(sub.Name) try: if "Named References" not in subNames: named_subcat = revit.doc.Settings.Categories.NewSubcategory( ref_plane_cat, "Named References") named_subcat.LineColor = DB.Color(128, 0, 255) named_subcat.SetLinePatternId( ref_plane_cat.GetLinePatternId( DB.GraphicsStyleType.Projection), DB.GraphicsStyleType.Projection, ) named_subcat_id = named_subcat.Id if "Weak References" not in subNames: weak_subcat = revit.doc.Settings.Categories.NewSubcategory( ref_plane_cat, "Weak References") weak_subcat.LineColor = DB.Color(255, 0, 128) # weak_subcat.SetLineWeight(5, DB.GraphicsStyleType.Projection) weak_subcat.SetLinePatternId( ref_plane_cat.GetLinePatternId( DB.GraphicsStyleType.Projection), DB.GraphicsStyleType.Projection,
def toRevitColor(color): r, g, b = color.split(",") return DB.Color(int(r), int(g), int(b))
else: num = 1 selected_color_R = selected_color[num] num = num+1 selected_color_G = selected_color[num] num = num+1 selected_color_B = selected_color[(num)] #----------SETUP COLORS FOR CHECKING---------- check_non_white = [] check_white = [] bg_check = [] #color_non_white = DB.Color(0,0,0) color_non_white = DB.Color(selected_color_R,selected_color_G,selected_color_B) color_white = DB.Color(255,255,255) check_non_white.append(color_non_white.Red) check_non_white.append(color_non_white.Green) check_non_white.append(color_non_white.Blue) check_white.append(color_white.Red) check_white.append(color_white.Green) check_white.append(color_white.Blue) #--------------------------------------------- #bg_col = app.BackgroundColor # #bg_check.append(bg_col.Red) #bg_check.append(bg_col.Green) #bg_check.append(bg_col.Blue)