-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathL9_PutBreakOnSectionFraming.py
More file actions
426 lines (362 loc) · 14.2 KB
/
L9_PutBreakOnSectionFraming.py
File metadata and controls
426 lines (362 loc) · 14.2 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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
import clr
import System
from System.Collections.Generic import*
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import*
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import*
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI 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
doc = DocumentManager.Instance.CurrentDBDocument
view = doc.ActiveView
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
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
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
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 Isparael(p,q):
return p.CrossProduct(q).IsZeroLength()
def FilterVerticalPlanar(lstPlface): # Get Vertical PlanarFaces
faV = []
x = XYZ.BasisX # You can change that value to have a new direction
for i in lstPlface:
faNomal = i.FaceNormal
check = Isparalel(x,faNomal)
if check == True:
faV.append(i)
return faV
def FilterHorizontalPlanar(lstPlface): # Get Horizaontal PlanarFaces
faH = []
z = XYZ.BasisZ
for i in lstPlface:
check = Isparael(z, i.FaceNormal)
if check == True:
faH.append(i)
return faH
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 lstFlattenL1(list):
result = []
for i in list:
result.append(i)
return result
def lstFlattenL2(list):
result = []
for i in list:
for j in i:
result.append(j)
return result
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
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
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 LineOffset(line,distance,direct): # Offset a line from one line earlier
convert = distance/304.8
if direct == "x" or "X": newVector = XYZ(convert,0,0)
if direct == "y" or "Y": newVector = XYZ(0,convert,0)
if direct == "z" or "Z": newVector = XYZ(0,0,convert)
# newVector = XYZ(convert,0,0)
# newVector = XYZ(0,0,convert)
trans = Transform.CreateTranslation(direct) # Setting direction for GetLinMin
lineMove = line.CreateTransformed(trans)
return lineMove
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 Isparael(NorLo, NorRevit):
re.append(i)
return re
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
def getTopFacesEle(planar):
re = []
z =XYZ.BasisX
remove = RemoveFaceNone(planar)
for i in remove:
var = i.FaceNormal
rad = var.AngleTo(XYZ.BasisZ)
if (rad*180)/3.14 < 10 :
re.append(i)
return re
def getIntersection(face, line):
re = []
results = clr.Reference[IntersectionResultArray]()
intersect = face.Intersect(line, results)
if intersect == SetComparisonResult.Overlap:
var1 = results.Item[0]
var2 = var1.XYZPoint
re.append(var2)
return re
def PointOffset1(lstPoint, dis, face):
re = []
if len(lstPoint) > 1:
ptsX = [i.X for i in lstPoint]
maxX = max(ptsX)
for i in lstPoint:
if i.X == maxX:
re.append(XYZ(-1*dis/308.4 + i.X,i.Y,i.Z))
else:
re.append(XYZ(1*dis/308.4+i.X,i.Y,i.Z))
else:
ptsCompare = face.Origin.X
for i in lstPoint:
if i.X > ptsCompare: re.append(XYZ(-1*dis/308.4 + i.X,i.Y,i.Z))
else: re.append(XYZ(1*dis/308.4 +i.X, i.Y,i.Z))
return re
def PointOffset2(lstPoint, face, dis,view):
x = view.RightDirection.X
y = view.RightDirection.Y
re = []
if len(lstPoint) > 1:
ptsX =[i.X for i in lstPoint]
mX = max(ptsX)
for i in lstPoint:
if x < 0 and y == -1: # Horizaontal
if i.X == mX:
re.append(XYZ(i.X, -1*dis/304.8 + i.Y, i.Z))
else: # Vertical
re.append(XYZ(i.X, 1*dis/304.8 + i.Y, i.Z))
else:
if i.X == mX:
re.append(XYZ(-1*dis/304.8 + i.X, i.Y, i.Z)) # left
else:
re.append(XYZ(dis/304.8 + i.X, i.Y, i.Z)) # right
else:
ptsCompare = face.Origin.X # Only one floor
for i in lstPoint:
if i.X > ptsCompare:
re.append(XYZ(-1*dis/304.8 + i.X, i.Y, i.Z))
else:
re.append(XYZ(dis/304.8 + i.X, i.Y, i.Z))
return re
fls = FilteredElementCollector(doc, view.Id).ToElements()
AllEle = []
rebars = []
eleFloors = []
eleFraming = []
for i in fls:
try:
if i.Category.Name == "Structural Framing":
eleFraming.append(i)
if i.Category.Name == "Floors":
eleFloors.append(i)
if i.Category.Name == "Structural Framing" or i.Category.Name == "Floors":
AllEle.append(i)
if i.Category.Name == "Structural Rebar":
rebars.append(i)
except:
pass
#OUT = AllEle, rebars , eleFloors , eleFraming
####--------------------------------------STEP 1-----------------------------####
getGeoFraming = [GetGeoElement(i) for i in eleFraming]
getGeoFloors = [GetGeoElement(i) for i in eleFloors]
getGeoAllEle = [GetGeoElement(i) for i in AllEle]
OUT = getGeoFraming, getGeoFloors , getGeoAllEle
getSolidFraming = [GetSolidFromGeo(i) for i in getGeoFraming]
getSolidFloors = [GetSolidFromGeo(i) for i in getGeoFloors]
getSolidAllEle = [GetSolidFromGeo(i) for i in getGeoAllEle]
OUT = getSolidFraming, getSolidFloors , getSolidAllEle
getFaceFraming = [GetPlanarFormSolid(i) for i in getSolidFraming]
getFaceFloors = [GetPlanarFormSolid(i) for i in getSolidFloors]
getFaceAllEle = [GetPlanarFormSolid(i) for i in getSolidAllEle]
OUT = getFaceFraming, getFaceFloors, getFaceFloors
OUT = [t.ToProtoType() for i in getFaceFraming for t in i ]
####--------------------------------------STEP 2-----------------------------####
getFaHoriFraming = [FilterHorizontalPlanar(i) for i in getFaceFraming]
getFaHoriFloor = [FilterHorizontalPlanar(i) for i in getFaceFloors]
getFaHoriAllEle = [FilterHorizontalPlanar(i) for i in getFaceAllEle]
OUT = getFaHoriFraming , getFaHoriFloor, getFaHoriAllEle
OUT = [t.ToProtoType() for i in getFaHoriAllEle for t in i ]
###--------------------------------------dict.fromkeys(list) or Set()-----------------------------####
re = []
reduceZ = set()
for i in getFaHoriAllEle:
for j in i:
if j.Origin.Z not in reduceZ:
reduceZ.add(j.Origin.Z)
re.append(j)
OUT = re
getFaHoriAllEle = re
####---------------------------------------------------------------------------------------####
getFaVerFraming = [FilterVerticalPlanar(i) for i in getFaceFraming]
getFaVerFloors = [FilterVerticalPlanar(i) for i in getFaceFloors]
getFaVerAllEle = [FilterVerticalPlanar(i) for i in getFaceAllEle]
OUT = [t.ToProtoType() for i in getFaVerAllEle for t in i ]
#OUT = getFaVerAllEle
####--------------------------------------STEP 3-----------------------------####
# Choose Right Or Left From User
rightFaceFraimg = [getRightDbPlanarFaces(i,view) for i in getFaVerFraming]
leftFaceFraimg = [getLeftDbPlanarFaces(i,view) for i in getFaVerFraming]
#OUT = [i.ToProtoType() for i in leftFaceFraimg]
rightFaceFloor = [getRightDbPlanarFaces(i,view) for i in getFaVerFloors]
leftFaceFloor = [getLeftDbPlanarFaces(i,view) for i in getFaVerFloors]
#OUT = [i.ToProtoType() for i in rightFaceFloor]
chooseFaceFraming = GetRightOrLeftFace(lstFlattenL2(getFaVerFraming),IN[1],view) # GetRightOrLeftFace not get list input
#OUT = [chooseFaceFraming.ToProtoType()]
chooseFaceFraming = [chooseFaceFraming]
####--------------------------------------STEP 4-----------------------------####
getLineFraming = [RetrieveEdgesFace(i) for i in chooseFaceFraming]
OUT = [j.ToProtoType() for i in getLineFraming for j in i]
OUT = lstFlattenL2(getLineFraming)
getVlineFraming = GetLineVertical(lstFlattenL2(getLineFraming))
OUT = [i.ToProtoType() for i in getVlineFraming]
OUT = getVlineFraming
####--------------------------------------STEP 5-----------------------------####
vLineOffsetFraming = LineOffset(getVlineFraming[0],IN[3],XYZ(IN[3]/304.8,0,0))
OUT = vLineOffsetFraming.ToProtoType(),[j.ToProtoType() for i in getLineFraming for j in i]
####--------------------------------------STEP 6-----------------------------####
getFBotFraming = [GetTopOrBotFace(lstFlattenL2(getFaHoriFraming),IN[2])]
TopandBotFace = [i.ToProtoType() for i in getFBotFraming]
OUT = TopandBotFace
####--------------------------------------STEP 7-----------------------------####
getLineBotFraming = [RetrieveEdgesFace(i) for i in getFBotFraming]
OUT = [j.ToProtoType() for i in getLineBotFraming for j in i]
getHLineFraming = [GetLineMin(i) for i in getLineBotFraming]
OUT = [i.ToProtoType() for i in getHLineFraming]
hLineOffsetFraming = LineOffset(getHLineFraming[0],IN[3],XYZ(0,0,IN[3]/304.8))
OUT = hLineOffsetFraming.ToProtoType() , getHLineFraming[0].ToProtoType()
####--------------------------------------STEP 8-----------------------------####
# Show all offset line
OUT = hLineOffsetFraming.ToProtoType() , getHLineFraming[0].ToProtoType(), vLineOffsetFraming.ToProtoType(),[j.ToProtoType() for i in getLineFraming for j in i]
# ####--------------------------------------STEP 9-----------------------------####
#getRefArray - H
getRefHoriAllele = GetReferenceArray(getFaHoriAllEle)
OUT = getRefHoriAllele
# ####--------------------------------------STEP 10-----------------------------####
# #GetRefArray - V
# getVFace = [GetMaxface(i) for i in getFaVerFraming]
# getRefVertiFraming = GetReferenceArray(getVFace)
TransactionManager.Instance.EnsureInTransaction(doc)
dimV = doc.Create.NewDimension(view, vLineOffsetFraming, getRefHoriAllele)
TransactionManager.Instance.TransactionTaskDone()
# OUT = dimV
faceTopFraming = GetRightOrLeftFace(lstFlattenL2(getFaVerFraming),True,view)
ptsUse = []
if len(eleFloors)> 0:
ptsFlatten = []
ptsIntersect = []
ptsRemove = []
###----------------------------------------CropView-----------------------------####
cropview = view.GetCropRegionShapeManager().GetCropShape()
####---------------------------------------GetLineVertical----------------------####
lineCrop = lstFlattenL2([GetLineVertical(i) for i in cropview])
OUT = lineCrop,[i.ToProtoType() for i in lineCrop]
###----------------------------------------Geometry-----------------------------####
geoFloors = [GetGeoElement(i) for i in eleFloors]
solid = GetSolidFromGeo(lstFlattenL2(geoFloors))
plannarFloors = GetPlanarFormSolid(solid)
faceTopFloor = GetTopFacesEle(plannarFloors)
for i in faceTopFloor:
for j in lineCrop:
ptsIntersect.append(GetIntersection(i,j))
ptsFlatten =lstFlattenL2(ptsIntersect)
ptsRemove = list(filter(None,ptsFlatten))
ptsUse = PointOffset2(ptsRemove,80,faceTopFraming, view)
OUT = ptsRemove
familyBreak = []
TransactionManager.Instance.EnsureInTransaction(doc)
for i in ptsUse:
faceBreak = doc.Create.NewFamilyInstance(i,UnwrapElement(IN[4]),view)
familyBreak.append(faceBreak)
TransactionManager.Instance.TransactionTaskDone()