1
+ # -*- coding: utf-8 -*-
2
+
3
+ __title__ = "DoorFlipState"
4
+ __author__ = "Jakob Steiner"
5
+ __doc__ = """Version = 0.3
6
+ Date = 13.04.2025
7
+ _____________________________________________________________________
8
+ Description:
9
+
10
+ Writes the flip state (aka Left/Right) of doors back to an instance
11
+ parameter 'Flügel Aufgehrichtung' in doors. This needs to be an instance
12
+ parameter of type text with the option different values for group instances.
13
+ Prints a summary of
14
+ accomplished job. All families to treat need 2 shared parameters
15
+ 'Türfamilienaufgehrichtung_standard'
16
+ 'Türfamilienaufgehrichtung_gespiegelt'
17
+ as instances with values corresponding, as in family defined standard
18
+ to write back to parameter 'Türaufgehrichtung'. For families who have
19
+ a symtetry chechbox standard value my be changed by conditional
20
+ statement in family:
21
+ (f.ex -> if(Anschlagseite gespiegelt, "Tür Rechts", "Tür Links"))
22
+
23
+ _____________________________________________________________________
24
+ Prerequisites:
25
+ In familys as instance, standard value as "blocked" formula
26
+ [Parameter] - 'Türfamilienaufgehrichtung_standard'
27
+ [Parameter] - 'Türfamilienaufgehrichtung_gespiegelt'
28
+
29
+ In project as instance:
30
+ [Parameter] - 'Flügel Aufgehrichtung'
31
+ _____________________________________________________________________
32
+ Last update:
33
+
34
+ - V 0.1 Creation(24.05.2021)
35
+ - V 0.2 (07.06.2021)
36
+ - Refactored
37
+ - Show Family/Types that did not have parameters set.
38
+ - V 0.3 (13.04.2025)
39
+ - List changes in doors
40
+ _____________________________________________________________________
41
+
42
+ """
43
+ #--------------------------------------------------------------------------------------------------------------------
44
+ #IMPORTS
45
+ # System
46
+ import time , sys
47
+ #pyRevit
48
+ from pyrevit import script
49
+
50
+ from Autodesk .Revit .DB import *
51
+ from collections import defaultdict
52
+
53
+ doc = __revit__ .ActiveUIDocument .Document
54
+ uidoc = __revit__ .ActiveUIDocument
55
+ app = __revit__ .Application
56
+ output = script .get_output ()
57
+ #--------------------------------------------------------------------------------------------------------------------
58
+ #GLOBAL PARAMETERS
59
+ TUERAUFG_STANDARD_PARAMETER = "Türfamilienaufgehrichtung_standard"
60
+ TUERAUFG_STANDARD_GESPIEGELT_PARAMETER = "Türfamilienaufgehrichtung_gespiegelt"
61
+ TUERAUFG_WRITEBACK_PARAMETER = "Flügel Aufgehrichtung"
62
+ TUERAUFG_ERROR_VALUE = "-" # Value if the family does't have shared param. above
63
+
64
+ #--------------------------------------------------------------------------------------------------------------------
65
+ #MAIN
66
+ timer_start = time .time ()
67
+
68
+ # GET ALL DOORS
69
+ doors_collector = FilteredElementCollector (doc ).OfCategory (BuiltInCategory .OST_Doors ).WhereElementIsNotElementType ().ToElements ()
70
+ if not doors_collector :
71
+ sys .exit ("No doors were found in the project." )
72
+
73
+ # FUNCTION TO CHECK IF PARAMETER EXISTS
74
+ def parameter_exists (parameter_name ):
75
+ binding_map = doc .ParameterBindings
76
+ iterator = binding_map .ForwardIterator ()
77
+ iterator .Reset ()
78
+ while iterator .MoveNext ():
79
+ if iterator .Key .Name == parameter_name :
80
+ return True
81
+ return False
82
+
83
+ # CHECK IF TUERAUFG_WRITEBACK_PARAMETER EXISTS
84
+ if not parameter_exists (TUERAUFG_WRITEBACK_PARAMETER ):
85
+ print ("The parameter '{}' does not exist in the current document." .format (TUERAUFG_WRITEBACK_PARAMETER ))
86
+ print ("Please create the parameter as an instance parameter, option different values for groupes," )
87
+ print ("for the category doors in the project." )
88
+
89
+ sys .exit ()
90
+
91
+ # CREATE CONTAINERS
92
+ count_parameter = 0
93
+ count_not_parameter = 0
94
+ doors_without_parameter = []
95
+ data_doors_changed = []
96
+
97
+ t = Transaction (doc ,__title__ )
98
+ t .Start ()
99
+ # CREATE A DICT FOR DOORS WITH CHANGED PARAMETERS
100
+ door_changed = []
101
+ # LOOP THROUGH ALL DOORS
102
+ for door in doors_collector :
103
+ # GET VALUE
104
+ try :
105
+ if door .Mirrored :
106
+ value = door .LookupParameter (TUERAUFG_STANDARD_GESPIEGELT_PARAMETER ).AsString ()
107
+ else :
108
+ value = door .LookupParameter (TUERAUFG_STANDARD_PARAMETER ).AsString ()
109
+ count_parameter += 1
110
+
111
+ except :
112
+ # IF VALUE IS UNAVAILABLE - USE DEFAULT ERROR VALUE
113
+ value = TUERAUFG_ERROR_VALUE
114
+ count_not_parameter += 1
115
+
116
+ # LOG DOOR TYPE WITHOUT VALUE
117
+ door_family = door .get_Parameter (BuiltInParameter .ELEM_FAMILY_PARAM ).AsValueString ()
118
+ door_type = door .get_Parameter (BuiltInParameter .ELEM_TYPE_PARAM ).AsValueString ()
119
+ door_name = "{family}-{type}" .format (family = door_family , type = door_type )
120
+ if door_name not in doors_without_parameter :
121
+ doors_without_parameter .append (door_name )
122
+
123
+ # SET PARAMETER
124
+ try :
125
+ # CHECK IF THE WRITEBACK PARAMETER EXISTS
126
+ door_out_param = door .LookupParameter (TUERAUFG_WRITEBACK_PARAMETER )
127
+
128
+ # WRITE CHANGES IN PARAMETERS
129
+ door_out_param_old = door .LookupParameter (TUERAUFG_WRITEBACK_PARAMETER ).AsString ()
130
+ door_out_param_new = value
131
+ if door_out_param_old != door_out_param_new :
132
+ data_doors_changed .append (door_changed )
133
+ door_out_param_changed = "{} -> {}" .format (door_out_param_old , door_out_param_new )
134
+ door_changed .append (door .Name )
135
+ door_changed .append (door_out_param_changed )
136
+ door_changed_link = output .linkify (door .Id )
137
+ door_changed .append (door_changed_link )
138
+ # SET DOOR FLIP STATE TO THE WRITEBACK PARAMETER
139
+ door_out_param .Set (str (value ))
140
+ except :
141
+ print ("Please make sure OUT instance parameter exists: {}" .format (TUERAUFG_WRITEBACK_PARAMETER ))
142
+ sys .exit ()
143
+ t .Commit ()
144
+
145
+ # FINAL PRINT
146
+ output .print_md ("\n Number of doors found in the project: {} " .format (len (doors_collector )))
147
+ output .print_md ("of theese with writeback parameters defined in door family: {}" .format (count_parameter ))
148
+ output .print_md ("without writeback parameters defined in door family: {a}" .format (a = count_not_parameter ,))
149
+ output .print_md ("The default writeback value for doors without defined values will be : " '"{b}"' " " .format (b = TUERAUFG_ERROR_VALUE ))
150
+ output .print_md ("****************************************************************" )
151
+ print ("door families without writeback parameter defined in family:" )
152
+ for door_type in doors_without_parameter :
153
+ print (door_type )
154
+
155
+ print ("****************************************************************" )
156
+ print ("Changes to previous run of the script:" )
157
+
158
+ # Create a table for changed parameter values
159
+ if data_doors_changed :
160
+ output .print_table (table_data = data_doors_changed , title = "Doors with changed parameters:" , columns = ["Door" , "Changed Value" , "ElementId" ])
161
+ else :
162
+ output .print_md ("No doors with changed parameters were found." )
163
+
164
+ # End
165
+ output .print_md ('---' )
166
+ output .print_md ('#### Script has finished in {}s' .format (time .time () - timer_start ))
0 commit comments