-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIfcOpening_IfcWindowOld1.py
140 lines (97 loc) · 6.54 KB
/
IfcOpening_IfcWindowOld1.py
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
import fme
import fmeobjects
import uuid
import time
import tempfile
import ifcopenshell, ifcopenshell.geom
class FeatureProcessor(object):
def input(self, feature):
O = 0., 0., 0.
X = 1., 0., 0.
Y = 0., 1., 0.
Z = 0., 0., 1.
# Helper function definitions
# Creates an IfcAxis2Placement3D from Location, Axis and RefDirection specified as Python tuples
def create_ifcaxis2placement(ifcfile, point=O, dir1=Z, dir2=X):
point = ifcfile.createIfcCartesianPoint(point)
dir1 = ifcfile.createIfcDirection(dir1)
dir2 = ifcfile.createIfcDirection(dir2)
axis2placement = ifcfile.createIfcAxis2Placement3D(point, dir1, dir2)
return axis2placement
# Creates an IfcLocalPlacement from Location, Axis and RefDirection, specified as Python tuples, and relative placement
def create_ifclocalplacement(ifcfile, point=O, dir1=Z, dir2=X, relative_to=None):
axis2placement = create_ifcaxis2placement(ifcfile,point,dir1,dir2)
ifclocalplacement2 = ifcfile.createIfcLocalPlacement(relative_to,axis2placement)
return ifclocalplacement2
# Creates an IfcPolyLine from a list of points, specified as Python tuples
def create_ifcpolyline(ifcfile, point_list):
ifcpts = []
for point in point_list:
point = ifcfile.createIfcCartesianPoint(point)
ifcpts.append(point)
polyline = ifcfile.createIfcPolyLine(ifcpts)
return polyline
# Creates an IfcExtrudedAreaSolid from a list of points, specified as Python tuples
def create_ifcextrudedareasolid(ifcfile, point_list, ifcaxis2placement, extrude_dir, extrusion):
polyline = create_ifcpolyline(ifcfile, point_list)
ifcclosedprofile = ifcfile.createIfcArbitraryClosedProfileDef("AREA", None, polyline)
ifcdir = ifcfile.createIfcDirection(extrude_dir)
ifcextrudedareasolid = ifcfile.createIfcExtrudedAreaSolid(ifcclosedprofile, ifcaxis2placement, ifcdir, extrusion)
return ifcextrudedareasolid
create_guid = lambda: ifcopenshell.guid.compress(uuid.uuid1().hex)
# Obtain references to master file
filename = FME_MacroValues['OUTPUT_FILE_PATH']
ifcfile = ifcopenshell.open(filename)
owner_history = ifcfile.by_type("IfcOwnerHistory")[0]
project = ifcfile.by_type("IfcProject")[0]
context = ifcfile.by_type("IfcGeometricRepresentationContext")[0]
building_storey = ifcfile.by_guid(feature.getAttribute('storey_guid'))
wall = ifcfile.by_guid(feature.getAttribute('wall_guid'))
wall_placement = wall.ObjectPlacement
# create point list for polyline
p0 = feature.getAttribute('axis_polyline{0}').split(',')
point0 = [float(x) for x in p0]
p1 = feature.getAttribute('axis_polyline{1}').split(',')
point1 = [float(x) for x in p1]
# Create and associate an opening for the window in the wall
opening_placement = create_ifclocalplacement(ifcfile, (0.0, 0.0, 0.0), (0.0, 0.0, 1.0), (1.0, 0.0, 0.0), wall_placement)
opening_extrusion_placement = create_ifcaxis2placement(ifcfile, (0.0, 0.0, 0.0), (0.0, 0.0, 1.0), (1.0, 0.0, 0.0))
point_list_opening_extrusion_area = [feature.getAttribute('p0'), feature.getAttribute('p1'), feature.getAttribute('p2'), feature.getAttribute('p3'), feature.getAttribute('p4')]
opening_solid = create_ifcextrudedareasolid(ifcfile, point_list_opening_extrusion_area, opening_extrusion_placement, (0.0, 0.0, 1.0), feature.getAttribute('Dimensions.Height'))
opening_representation = ifcfile.createIfcShapeRepresentation(context, "Body", "SweptSolid", [opening_solid])
opening_shape = ifcfile.createIfcProductDefinitionShape(None, None, [opening_representation])
opening_element = ifcfile.createIfcOpeningElement(create_guid(), owner_history, "Opening", "An awesome opening", None, opening_placement, opening_shape, None, "OPENING")
ifcfile.createIfcRelVoidsElement(create_guid(), owner_history, None, None, wall, opening_element)
s = ifcopenshell.geom.settings()
s.set(s.DISABLE_TRIANGULATION, True)
s.set(s.USE_BREP_DATA, True)
window_geom_temp1 = FME_MacroValues['geom_temp1']
ifcfile_temp_window = ifcopenshell.open(window_geom_temp1)
window = []
window = ifcfile_temp_window.by_type('IfcWindow')
for w in window:
w_guid = w.GlobalId
c = ifcfile_temp_window[w_guid]
#Swig Object
shp = ifcopenshell.geom.create_shape(s, c)
new_window = shp.geometry.brep_data
# Create a simplified representation for the Window
#window_placement = create_ifclocalplacement(ifcfile, (0.0, 0.0, 0.0), (0.0, 0.0, 1.0), (1.0, 0.0, 0.0), opening_placement)
#window_extrusion_placement = create_ifcaxis2placement(ifcfile, (0.0, 0.0, 0.0), (0.0, 0.0, 1.0), (1.0, 0.0, 0.0))
#point_list_window_extrusion_area = [feature.getAttribute('p0'), feature.getAttribute('p1'), feature.getAttribute('p2'), feature.getAttribute('p3'), feature.getAttribute('p4')]
#window_solid = create_ifcextrudedareasolid(ifcfile, point_list_window_extrusion_area, window_extrusion_placement, (0.0, 0.0, 1.0), feature.getAttribute('Dimensions.Height'))
#window_representation = ifcfile.createIfcShapeRepresentation(context, "Body", "SweptSolid", [shp])
#window_shape = ifcfile.createIfcProductDefinitionShape(None, None, [window_representation])
#window = ifcfile.createIfcWindow(create_guid(), owner_history, feature.getAttribute('FamilyType'), feature.getAttribute('Family'), None, window_placement, window_shape, None, None)
feature.setAttribute('testwindow', str(new_window))
#feature.setAttribute('windowguid', str(w))
feature.setAttribute('window_geom_temp1', str(window_geom_temp1))
feature.setAttribute('wall_placement', str(wall_placement))
feature.setAttribute('point_list_opening_extrusion_area', str(point_list_opening_extrusion_area))
# Write the contents of the file to disk
#ifcfile.write(filename)
self.pyoutput(feature)
def close(self):
pass
def process_group(self):
pass