-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGet_Line_Framing_Grid_OfGeometry..py
More file actions
247 lines (212 loc) · 6.93 KB
/
Get_Line_Framing_Grid_OfGeometry..py
File metadata and controls
247 lines (212 loc) · 6.93 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
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
class SelectionFilter(ISelectionFilter):
def __init__(self, ctgName1 , ctgName2, ctgName3):
self.ctgName1 = ctgName1
self.ctgName2 = ctgName2
self.ctgName3 = ctgName3
def AllowElement(self, element):
if element.Category.Name == self.ctgName1 or element.Category.Name == self.ctgName2 or element.Category.Name == self.ctgName3:
return True
else:
return False
def AllowReference(ref, xyZ):
return False
def GridsFirstEnd(lstGrids):
keySelect =[]
ptsGrids =[]
for i in lstGrids:
crv = i.Curve
ptsGrids.append(crv.GetEndPoint(0).X)
ptsMaxMin = [max(ptsGrids),min(ptsGrids)]
for i in lstGrids:
var = i.Curve
x = var.GetEndPoint(0).X
for j in ptsMaxMin:
if j==x:
keySelect.append(i)
return keySelect
def RefArrayFromGrids(listGrids,doc):
refArray = ReferenceArray()
#dùng để phân tích hình học.
opt = Options()
opt.ComputeReferences= True#Xác định xem các tham chiếu đến các đối tượng hình học có được tính toán hay không.
opt.IncludeNonVisibleObjects = True#Có trích xuất các đối tượng hình học phần tử ẩn không
opt.View = doc.ActiveView#Khung nhìn được sử dụng để trích xuất hình học.
for i in elSelect:
crv = i.Curve
for j in i.get_Geometry(opt):
if isinstance(j,Line):
grRef = j.Reference
refArray.Append(grRef)
return refArray
def CurveFromGrids(listGrids,doc):
crv = []
#dùng để phân tích hình học.
opt = Options()
opt.ComputeReferences= True#Xác định xem các tham chiếu đến các đối tượng hình học có được tính toán hay không.
opt.IncludeNonVisibleObjects = True#Có trích xuất các đối tượng hình học phần tử ẩn không
opt.View = doc.ActiveView#Khung nhìn được sử dụng để trích xuất hình học.
for i in elSelect:
cr = i.Curve
crv.append(cr)
return crv
def getDbLineFromLine(lstLine):
re = []
for i in lstLine:
re.append(i.GeometryCurve)
return re
#line1 = RefArrayByDBLine(getVLineMin_Framing)
def getEdgesByPlanar(lstPlanar):
re = []
var = lstPlanar.EdgeLoops
for i in var:
re.append(i)
return re
#OUT = [GetEdgesByPlanar(j) for i in getMaxFaceFraming for j in i]
def getRefByPlanar(lstPlanar):
re = []
var = lstPlanar.EdgeLoops
for i in var:
for j in i:
re.append(j.Reference)
return re
#OUT = [GetRefByPlanar(j) for i in getMaxFaceFraming ]
def OffsetPoint (line,distance):
base =XYZ.BasisZ
sp = line.GetEndPoint(0)
ep = line.GetEndPoint(1)
vt = (sp+ep).CrossProduct(base).Normalize()
pstnew = sp+distance*vt
return vt
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 Isparalel(p,q):
return p.CrossProduct(q).IsZeroLength()
def RemoveFaceNone(dbPlanarFaces): # Get planarFaces Not Null Value
pfaces = []
for i in dbPlanarFaces:
if i.Reference != None:
pfaces.append(i)
return pfaces
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 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 getLineMax(lstLine): # Get a min line of list line
_length = []
lineMax = []
for i in lstLine:
_length.append(i.Length)
for j in lstLine:
if j.Length == max(_length):
lineMax.append(j)
return lineMax
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
###--------------------------------------- Step 1 -------------------------------###
ele = SelectionFilter("Grids", "Lines", "Structural Framing")
elSelectAll = uidoc.Selection.PickElementsByRectangle(ele,"Selects")
OUT = elSelectAll
###--------------------------------------- Step 2 -------------------------------###
lines = []
grids = []
eleFraming = []
for i in elSelectAll:
if i.Category.Name == "Lines": lines.append(i)
if i.Category.Name == "Grids": grids.append(i)
if i.Category.Name == "Structural Framing": eleFraming.append(i)
OUT = lines, grids, eleFraming
elSelect= [grids[0]]
vtxPlane = XYZ.BasisZ
vtxSection = XYZ.BasisY
crvGrids= CurveFromGrids(elSelect,doc)
ptsGris1 = crvGrids[0].GetEndPoint(0)
ptsGris2 = crvGrids[0].GetEndPoint(1)
vtxFromGrids = ptsGris1-ptsGris2
#OUT = line.ToProtoType(), elSelect
refGids = RefArrayFromGrids(elSelect,doc)
pickPoint = uidoc.Selection.PickPoint("Select Point")
direct = vtxPlane.CrossProduct(vtxFromGrids) # Nhân hai vector (0,0,1)*(0,1,0)=(1,0,0) is line vuông góc với Grids
line = Line.CreateBound(pickPoint,pickPoint+direct) # Get đường vuông góc với Grid
OUT = line.ToProtoType()
getGeoFraming = [GetGeoElement(i) for i in eleFraming]
OUT = getGeoFraming , line