-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColorDesginOptions_script.py
More file actions
92 lines (73 loc) · 2.72 KB
/
ColorDesginOptions_script.py
File metadata and controls
92 lines (73 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# -*- coding: utf-8 -*-
import clr
clr.AddReference("RevitAPI")
clr.AddReference("System")
from System.Collections.Generic import List
from Autodesk.Revit.DB import FilteredElementCollector as Fec
from Autodesk.Revit.DB import BuiltInCategory as Bic
from Autodesk.Revit.DB import Transaction, FillPattern, FillPatternElement
from Autodesk.Revit.DB import OverrideGraphicSettings, View, ElementId
from Autodesk.Revit.DB import Category, Subelement, Document
import Autodesk
import re
import sys
import colorsys
from collections import namedtuple
from pyrevit import revit, DB
from pyrevit import forms
from pyrevit import script
from pyrevit import coreutils
from pyrevit.coreutils import pyutils
__doc__ = 'Visualizes the distribution of Design Options. ' \
# reference the current open revit model to work with:
doc = __revit__.ActiveUIDocument.Document
view = doc.ActiveView
# get all fill patterns
fill_patterns = Fec(doc).OfClass(FillPatternElement).WhereElementIsNotElementType().ToElements()
# get id of solid fill
solid_fill = fill_patterns[0].Id
# main -----------------------------------------------------------------------
# connect to revit model elements via FilteredElementCollector
elements = filter(None, Fec(doc, doc.ActiveView.Id).ToElements())
element_do = []
for element in elements:
element_do.append(element.LookupParameter("Entwurfsoption").AsString())
design_options = set(element_do)
# for i in design_options:
# print(i)
colors_hsv = []
for i in [x * 0.01 for x in range(0, 100, (99 / (len(design_options)-1)))]:
# print(i)
colors_hsv.append((i, 0.7, 0.9))
# print(colors_hsv)
def hsv2rgb(h,s,v):
return tuple(round(i * 255) for i in colorsys.hsv_to_rgb(h,s,v))
colors_rgb = []
for color in colors_hsv:
colors_rgb.append(hsv2rgb(color[0], color[1], color[2]))
# print(colors_rgb)
do_color = dict(zip(design_options, colors_rgb))
# print(do_color)
# create graphical overrides
ogs = OverrideGraphicSettings().SetSurfaceForegroundPatternId(solid_fill)
ogs.SetCutForegroundPatternId(solid_fill)
# entering a transaction to modify the revit model database
# start transaction
tx = Transaction(doc, "Visualize Design Options")
tx.Start()
for element in elements:
try:
color = do_color.get(element.LookupParameter("Entwurfsoption").AsString())
# print(color)
color_revit = Autodesk.Revit.DB.Color(color[0], color[1], color[2])
# print(color_revit)
# ogs.SetProjectionLineColor(color_revit)
ogs.SetSurfaceForegroundPatternColor(color_revit)
ogs.SetCutForegroundPatternColor(color_revit)
doc.ActiveView.SetElementOverrides((element.Id), ogs)
except:
pass
# commit the changes to the revit model database
# end transaction
tx.Commit()
# done.