-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path04_Template_List.py
More file actions
369 lines (337 loc) · 11.3 KB
/
04_Template_List.py
File metadata and controls
369 lines (337 loc) · 11.3 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
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
import clr
import System
import math
from System.Collections.Generic import *
clr.AddReference("ProtoGeometry")
from Autodesk.DesignScript.Geometry import *
# clr.AddReference('RevitAPI')
# import Autodesk
# from Autodesk.Revit.DB import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import*
from Autodesk.Revit.UI.Selection import*
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
import clr
clr.AddReference('DSCoreNodes')
from DSCore import *
doc = DocumentManager.Instance.CurrentDBDocument
view = doc.ActiveView
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
###################################List - Modifily #####################
def filtered(lstScores, number): # Filter number of list with a condition
fil = filter(lambda score: score < number, lstScores)
return (list(fil))
def filter_IsListInList(lst1,lst2):
re = []
for i in len(lst1):
re.append(i)
def chunks(l, n): #List.Chop
n = max(1, n)
return (l[i:i+n] for i in range(0, len(l), n))
def getIndexOfList(lst,index): # Get a Value from Level 3 of a list by Index Number
re = []
for i in lst:
c = i[index]
re.append(c)
return re
def lstFlattenL1(list): #List.Flatten
result = []
for i in list:
result.append(i)
return result
def lstFlattenL2(list): #List.Flatten
result = []
for i in list:
for j in i:
result.append(j)
return result
################################### GEOMETRY ELEMENTS #####################
def CreateLine(point1,point2): # Take Revit.DB.Line by XYZ.Bisis
line = Line.CreateBound(point1,point2)
return line
def ReferenceFromSurface(ElementSurface): # Get Revit.DB.Reference from Surface
ref = []
for i in ElementSurface:
re =[]
for j in i:
re.append(j.Tags.LookupTag("RevitFaceReference"))
ref.append(re)
return ref
#OUT = ReferenceFromSurface(UnwrapElement(IN[1]))
def getDBLineFormEleLine(ElementLines): # Get Revit.DB.Line from Curve Elements
opt = Options()
opt.ComputeReferences = True
opt.IncludeNonVisibleObjects = True
opt.View = doc.ActiveView
ln = []
for i in lines:
re =[]
for j in i:
re.append(UnwrapElement(j).ToRevitType())
ln.append(re)
return ln
#OUT = GetDBLineFormEleLine(IN[1])
def getReferenceOfGrid(ElementGrids): # Get Revit.DB.Reference from Grids
opt = Options()
opt.ComputeReferences = True
opt.IncludeNonVisibleObjects = True
opt.View = doc.ActiveView
refGrids = []
for i in UnwrapElement(ElementGrids):
f = (i.get_Geometry(opt))
[refGrids.append(j.Reference) for j in f if str(j).Contains("Line")]
return refGrids
#OUT = GetReferenceOfGrid(IN[1])
def Combine_EleSurface_EleCurve_RefGrids(EleCurve,EleSurface,RefGrids): # Combine Ref's Surface and Ref
Ref=[]
for i in range(0,len(EleSurface)):
dis =[]
for j in EleSurface[i]:
dis.append(EleCurve[i].DistanceTo(j))
if dis[0] !=0 and dis[1] !=0:
#su[i].insert(0,lst[i])
out = EleSurface[i].insert(0,RefGrids[i])
for i in range(0,len(EleSurface)):
re =[]
for j in EleSurface[i]:
if str(j).Contains('Surface'):
re.append(j.Tags.LookupTag("RevitFaceReference"))
else:
re.append(j)
Ref.append(re)
return Ref
#OUT = Combine_EleSurface_EleCurve_RefGrids(IN[1],IN[2],IN[3])
def getGeoElement(element): # Get geometry of element.
geo = []
opt = Options()
opt.ComputeReferences = True
opt.IncludeNonVisibleObjects = True
opt.DetailLevel = ViewDetailLevel.Fine
geoByElement = element.get_Geometry(opt)
geo = [i for i in geoByElement]
return geo
#getGeoFraming = [GetGeoElement(i) for i in eleFraming]
def getSolidFromGeo(lstGeo): # Get Solid from Geo
sol = []
for i in lstGeo:
if i.GetType()== Solid and i.Volume > 0:
sol.append(i)
elif i.GetType() == GeometryInstance:
var = i.SymbolGeometry
for j in var:
if j.Volume > 0:
sol.append(j)
return sol
#getSolidFraming = [GetSolidFromGeo(i) for i in getGeoFraming]
def getPlanarFormSolid(solids): # Get Planarface from solids
plaf = []
for i in solids:
var = i.Faces
for j in var:
if j.Reference != None:
plaf.append(j)
return plaf
def RemoveFaceNone(dbPlanarFaces): # Get planarFaces Not Null Value
pfaces = []
for i in dbPlanarFaces:
if i.Reference != None:
pfaces.append(i)
return pfaces
def Isparalel(p,q):
return p.CrossProduct(q).IsZeroLength()
def FilterVerticalPlanar(lstPlface): # Get Vertical PlanarFaces
faV = []
y = XYZ.BasisY
for i in lstPlface:
faNomal = i.FaceNormal
check = Isparalel(y,faNomal)
if check == True:
faV.append(i)
return faV
def getFaceVertical(plannar): # Get Vertical PlanarFaces
re = []
remove = RemoveFaceNone(plannar)
for i in remove:
var = i.FaceNormal
rad = var.AngleTo(XYZ.BasisZ)
if 30<(rad*180/3.14)<170:
re.append(i)
return re
#getFaVerFraming = [GetFaceVertical(i) for i in getFaceFraming]
def getMaxface(plananrs):
_Area = []
_face = []
for i in plananrs:
_Area.append(i.Area)
for j in plananrs:
if j.Area > (max(_Area)-min(_Area)):
_face.append(j)
return _face
#getFaMaxVerFraming = [GetMaxface(i) for i in getFaVerFraming]
def FilterHorizontalPlanar(lstPlface): # Get Horizaontal PlanarFaces
faH = []
z = XYZ.BasisZ
for i in lstPlface:
check = Isparalel(z, i.FaceNormal)
if check == True:
faH.append(i)
return faH
def getRightDbPlanarFaces(dbPlanarFaces,activeView): # Get Right PlanarFaces of a Element
direct = view.RightDirection
for i in dbPlanarFaces:
var = i.FaceNormal
if var.IsAlmostEqualTo(direct):
return i
def getLeftDbPlanarFaces(dbPlanarFaces,activeView): # Get Right PlanarFaces of a Element
direct = view.RightDirection
for i in dbPlanarFaces:
var = -1*i.FaceNormal
if var.IsAlmostEqualTo(direct):
return i
def getRightOrLeftPlanarFaces(dbPlanarFaces,reason,activeView): # Choose in one of Right and Left of Faces
if reason == True: return getRightDbPlanarFaces(dbPlanarFaces,activeView)
elif reason == False: return getLeftDbPlanarFaces(dbPlanarFaces, activeView)
def getTopOrBotFace(lstPlanars, reason): # Get Top or Bottom of Faces
for i in lstPlanars:
if i.FaceNormal.Z == 1 and reason == True:
return i
for i in lstPlanars:
if i.FaceNormal.Z == -1 and reason == False:
return i
def RetrieveEdgesFace(lstPlanar): # Get Lines of PlanarFaces
re = []
var = lstPlanar.EdgeLoops
for i in var:
for j in i:
re.append(j.AsCurve())
return re
#GetLineFraming = [RetrieveEdgesFace(i) for i in getFaVerFraming[0]]
def getLineMin(lstLine): # Get a min line of list line
_length = []
for i in lstLine:
_length.append(i.Length)
for j in lstLine:
if j.Length == min(_length):
return j
def getLineMax(lstLine): # Get a max line of list line
_length = []
for i in lstLine:
_length.append(i.Length)
for j in lstLine:
if j.Length == max(_length):
return j
def LineOffset(line,distance,direct): # Offset a line from one line earlier
convert = distance/304.8
newVector = None
# if direct == "x" or "X": newVector = XYZ(convert,0,0)
# if direct == "y" or "Y": newVector = XYZ(0,convert,0)
# elif direct == "z" or "Z": newVector = XYZ(0,0,convert)
newVector = XYZ(0,0,convert)
newVector = XYZ(0,convert,0)
trans = Transform.CreateTranslation(newVector) # Setting direction for GetLinMin
lineMove = line.CreateTransformed(trans)
return lineMove
def getReference(lstPlanar):
re = []
for i in lstPlanar:
re.append(i.Reference)
return re
def getReferenceArray(lstPlanar):
reArray = ReferenceArray()
for i in lstPlanar:
reArray.Append(i.Reference)
return reArray
def getLineVertical(lstLine): # Get vertical Line by Isparalel
re = []
NorRevit = XYZ.BasisZ
for i in lstLine:
NorLo = i.Direction
if Isparalel(NorLo, NorRevit):
re.append(i)
return re
class SelectionFilter(ISelectionFilter):
def __init__(self, ctgName1 , ctgName2):
self.ctgName1 = ctgName1
self.ctgName2 = ctgName2
def AllowElement(self, element):
if element.Category.Name == self.ctgName1 or element.Category.Name == self.ctgName2:
return True
else:
return False
def AllowReference(ref, xyZ):
return False
def LinebyGrids(lstGrids):
re = []
for i in lstGrids:
crv = i.Curve
re.append(crv)
return re
def LineOffset(line,distance,direct1, direct2, Flip): # Offset a line from one line earlier
convert = distance
#newVector = None
vt =XYZ.BasisY
checkY = Isparalel(vt,direct)
if checkY == True:
if direct1 == "x" or "X": dir = Flip*direct2*(1/304.8)*convert
else:
if direct1 == "y" or "Y": dir = Flip*direct2*(1/304.8)*convert
#if direct == "z" or "Z": newVector = XYZ(0,0,convert)
trans = Transform.CreateTranslation(dir) # Setting direction for GetLinMin
lineMove = line.CreateTransformed(trans)
return lineMove
#offsetline =LineOffset(line,IN[1],"X",directFraming, IN[2] )
def RefArrayByEleLine(linelist): # Get ReferenceArray by Element Line
refArray = []
for i in linelist:
rArr = ReferenceArray()
for l in i:
rArr.Append(Reference(l))
refArray.append(rArr)
return refArray
#OUT = RefArrayByEleLine(UnwrapElement(IN[2]))
###-------------------------GEOMETRY---------------------###
def getAngle(p1,p2):
xDiff = p2.X - p1.X
yDiff = p2.Y - p1.Y
radian = math.atan2(yDiff, xDiff) # Define Angle in Euclide Surface
angle = math.degrees(radian)
angle = abs(angle)
angle = round(angle)
return angle
# p1 = XYZ(0,0,1)
# p2 = XYZ(0,1,0)
# OUT = getAngle(p1,p2)
def distance(s,e):#Hypot is a mathematical function defined to calculate the length of the hypotenuse of a right-angle triangle
dist = math.hypot(e.X - s.X,e.Y-s.Y)
return dist
# p1 = Point.ByCoordinates(1,0)
# p2 = Point.ByCoordinates(10,10)
# OUT = distance(p1,p2)
def distance(p1,p2):
"""Caculates the distance between two points in 2D (XY) space"""
x = p2.X - p1.X
y = p2.Y - p1.Y
return math.sqrt(x**2 +y**2)
# p1 = Point.ByCoordinates(1,0)
# p2 = Point.ByCoordinates(10,10)
# OUT = distance(p1,p2)
def createLinesByTwoPoints(p1,p2):
line = Line.ByStartPointEndPoint(p1,p2)
return line
p1 = Point.ByCoordinates(1,0,10)
p2 = Point.ByCoordinates(10,10,0)
p3 = Point.ByCoordinates(10,5,7)
# l1 = createLinesByTwoPoints(p1,p2)
# l2 = createLinesByTwoPoints(p1,p3)
# OUT = l1,l2
# def AngleTwoLine(line1,line2):
# angle = line1.AngleTo(line2)
# return angle
# OUT = AngleTwoLine(l1,l2)