-
Notifications
You must be signed in to change notification settings - Fork 0
/
Duct_UpstreamComponents.dyf
200 lines (191 loc) · 7.31 KB
/
Duct_UpstreamComponents.dyf
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<Workspace Version="1.3.2.2480" X="-22" Y="31" zoom="1" ScaleFactor="1" Name="Duct_UpstreamComponents" Description="collects the upstream components from linput ducts" ID="6f194e01-ff77-4386-b7ef-2e2dbd50e2a4" Category="ArupBimSF.Revit.Mep_Mechanical">
<NamespaceResolutionMap />
<Elements>
<Dynamo.Graph.Nodes.CustomNodes.Output guid="db9acb11-d789-4113-864a-13e99264cd9e" type="Dynamo.Graph.Nodes.CustomNodes.Output" nickname="Output" x="1117" y="305" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="False" IsFrozen="false" isPinned="false">
<PortInfo index="0" default="False" />
<Symbol value="Elements" />
</Dynamo.Graph.Nodes.CustomNodes.Output>
<Dynamo.Graph.Nodes.CodeBlockNodeModel guid="50057e9f-af46-452e-a346-7e23fea9d079" type="Dynamo.Graph.Nodes.CodeBlockNodeModel" nickname="Code Block" x="964" y="317" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="False" IsFrozen="false" isPinned="false" CodeText="x[0];" ShouldFocus="false">
<PortInfo index="0" default="False" />
</Dynamo.Graph.Nodes.CodeBlockNodeModel>
<PythonNodeModels.PythonNode guid="720424d8-275a-4dac-8fc1-b7e8aec342e7" type="PythonNodeModels.PythonNode" nickname="Python Script" x="762" y="323" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="False" IsFrozen="false" isPinned="false" inputcount="2">
<PortInfo index="0" default="False" />
<PortInfo index="1" default="False" />
<Script>import clr
import math
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
#The inputs to this node will be stored as a list in the IN variables.
if isinstance(IN[0], list):
elements = UnwrapElement(IN[0])
else:
elements = [UnwrapElement(IN[0])]
def getSize(x):
try:
conns = x.ConnectorManager.Connectors
except:
conns = x.MEPModel.ConnectorManager.Connectors
maxsize = 0
for c in conns:
if c.Shape == ConnectorProfileType.Round:
startsize = c.Radius * 2
elif c.Shape == ConnectorProfileType.Invalid:
continue
else:
area = c.Width * c.Height
startsize = (math.sqrt(area/math.pi) * 2)
if startsize > maxsize:
maxsize = startsize
return maxsize
factor = IN[1]
def nextElement(elem,sys):
sysname = next.get_Parameter(BuiltInParameter.RBS_SYSTEM_CLASSIFICATION_PARAM).AsString()
for s in sysname.split(","):
if s in sys.split(","):
break
else:
return 4
if "Return Air" in sysname:
direction = FlowDirectionType.In
else:
direction = FlowDirectionType.Out
try:
connectors = elem.ConnectorManager.Connectors
for conn in connectors:
if conn.Domain != Domain.DomainHvac:
continue
elif conn.Direction == direction:
continue
else:
endconn = conn
for c in endconn.AllRefs:
if c.Owner.Id.Equals(elem.Id):
continue
elif c.Owner.GetType() == Mechanical.MechanicalSystem:
return 0
else:
newelem = c.Owner
return newelem
except AttributeError:
connectors = elem.MEPModel.ConnectorManager.Connectors
if connectors.Size == 1:
for conn in connectors:
if conn.Domain != Domain.DomainHvac:
continue
endconn = conn
if endconn.AllRefs.Size == 1:
for c in endconn.AllRefs:
if c.Owner.GetType() == Mechanical.MechanicalSystem:
return 1
for c in endconn.AllRefs:
if c.Owner.Id.Equals(elem.Id):
continue
elif c.Owner.GetType() == Mechanical.MechanicalSystem:
continue
else:
newelem = c.Owner
return newelem
elif connectors.Size == 2:
for conn in connectors:
if conn.Domain != Domain.DomainHvac:
continue
if conn.Direction == direction:
continue
else:
endconn = conn
if endconn.AllRefs.Size == 1:
for c in endconn.AllRefs:
if c.Owner.GetType() == Mechanical.MechanicalSystem:
return 2
for c in endconn.AllRefs:
if c.Owner.Id.Equals(elem.Id):
continue
elif c.Owner.GetType() == Mechanical.MechanicalSystem:
continue
else:
newelem = c.Owner
return newelem
else:
for conn in connectors:
if conn.Domain != Domain.DomainHvac:
continue
if conn.Direction != direction:
endconn = conn
if endconn.AllRefs.Size == 1:
for c in endconn.AllRefs:
if c.Owner.GetType() == Mechanical.MechanicalSystem:
return 3
for c in endconn.AllRefs:
if c.Owner.Id.Equals(elem.Id):
continue
elif c.Owner.GetType() == Mechanical.MechanicalSystem:
continue
else:
newelem = c.Owner
return newelem
result = []
endlist = []
for j,x in enumerate(elements):
listout = []
ids = []
sysclass = x.get_Parameter(BuiltInParameter.RBS_SYSTEM_CLASSIFICATION_PARAM).AsString()
startsize = getSize(x)
next = x
i = 0
while True:
if i > 1000:
result.append(next.Id.ToString() + ": end of loop")
break
try:
next = nextElement(next,sysclass)
i += 1
except Exception as e:
result.append(next.Id.ToString() + ": probably a direction error")
break
if isinstance(next, int):
result.append(next.ToString() + ": open end or different system classification")
break
if next.Id in ids:
result.append(next.Id.ToString() + ": double element")
break
i += 1
nextsize = getSize(next)
if nextsize > startsize * factor:
result.append(next.Id.ToString() + ": size end")
break
ids.append(next.Id)
listout.append(next)
endlist.append(listout)
#Assign your output to the OUT variable.
if len(endlist) == 1:
OUT = listout, result
else:
OUT = endlist, result</Script>
</PythonNodeModels.PythonNode>
<Dynamo.Graph.Nodes.CustomNodes.Symbol guid="ec17fa54-1b42-4013-973f-3a97aa4d18f0" type="Dynamo.Graph.Nodes.CustomNodes.Symbol" nickname="Input" x="436" y="426" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="True" IsFrozen="false" isPinned="false">
<Symbol value="SizeLimitFactor: int = 20" />
</Dynamo.Graph.Nodes.CustomNodes.Symbol>
<Dynamo.Graph.Nodes.CustomNodes.Symbol guid="eb902e95-52dd-45e7-aea7-68273fedec59" type="Dynamo.Graph.Nodes.CustomNodes.Symbol" nickname="Input" x="444" y="326" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="True" IsFrozen="false" isPinned="false">
<Symbol value="DuctElement" />
</Dynamo.Graph.Nodes.CustomNodes.Symbol>
</Elements>
<Connectors>
<Dynamo.Graph.Connectors.ConnectorModel start="50057e9f-af46-452e-a346-7e23fea9d079" start_index="0" end="db9acb11-d789-4113-864a-13e99264cd9e" end_index="0" portType="0" />
<Dynamo.Graph.Connectors.ConnectorModel start="720424d8-275a-4dac-8fc1-b7e8aec342e7" start_index="0" end="50057e9f-af46-452e-a346-7e23fea9d079" end_index="0" portType="0" />
<Dynamo.Graph.Connectors.ConnectorModel start="ec17fa54-1b42-4013-973f-3a97aa4d18f0" start_index="0" end="720424d8-275a-4dac-8fc1-b7e8aec342e7" end_index="1" portType="0" />
<Dynamo.Graph.Connectors.ConnectorModel start="eb902e95-52dd-45e7-aea7-68273fedec59" start_index="0" end="720424d8-275a-4dac-8fc1-b7e8aec342e7" end_index="0" portType="0" />
</Connectors>
<Notes />
<Annotations />
<Presets />
</Workspace>