-
Notifications
You must be signed in to change notification settings - Fork 0
/
IfcWindow_Glass.py
152 lines (95 loc) · 6.7 KB
/
IfcWindow_Glass.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
141
142
143
144
145
146
147
148
149
150
151
152
import fme
import fmeobjects
import uuid
import time
import tempfile
import ifcopenshell
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
# Creates an IfcExtrudedAreaSolid from IfcRectangleProfile
def create_ifcextrudedareasolid(ifcfile, point_list, ifcaxis2placement, extrude_dir, extrusion):
polyline = create_ifcpolyline(ifcfile, point_list)
ifc_rec_profile = ifcfile.createIfcRectangleProfileDef("AREA", feature.getAttribute('FamilyType'), None, feature.getAttribute('XDim'), feature.getAttribute('YDim'))
ifcdir = ifcfile.createIfcDirection(Z)
ifcextrudedareasolid = ifcfile.createIfcExtrudedAreaSolid(ifcclosedprofile, ifcaxis2placement, ifcdir, extrusion)
return ifcextrudedareasolid
create_guid = lambda: ifcopenshell.guid.compress(uuid.uuid1().hex)
# IFC template creation
filename = feature.getAttribute('path_rootname')+"_FME.ifc"
# Obtain references to instances defined in template
ifcfile = ifcopenshell.open(filename)
owner_history = ifcfile.by_type("IfcOwnerHistory")[0]
project = ifcfile.by_type("IfcProject")[0]
context = ifcfile.by_type("IfcGeometricRepresentationContext")[0]
# create point lists
#axisp0 = feature.getAttribute('axis_polyline{0}')
#loc = axisp0.split(',')
#location = [float(x) for x in loc]
#locationtype = type(location)
wall = ifcfile.by_guid(feature.getAttribute('wall_guid'))
wall_placement = wall.ObjectPlacement
#storey_ref = wall.ContainedInStructure
building_storey = ifcfile.get_inverse(wall)[1]
# 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)
# Create Window components - Glass
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))
window_solid = create_ifcextrudedareasolid(ifcfile, ifc_rec_profile, window_extrusion_placement, (0.0, 0.0, 1.0), feature.getAttribute('Dimensions.Height'))
window_representation = ifcfile.createIfcShapeRepresentation(context, "Body", "SweptSolid", [window_solid])
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)
# Relate the window to the opening element
ifcfile.createIfcRelFillsElement(create_guid(), owner_history, None, None, opening_element, window)
# Relate the window and wall to the building storey
ifcfile.createIfcRelContainedInSpatialStructure(create_guid(), owner_history, "Building Storey Container", None, [wall, window], building_storey)
# Write the contents of the file to disk
ifcfile.write(filename)
#feature.setAttribute('LocalPoint', str(location))
#feature.setAttribute('opening_location', str(location))
feature.setAttribute('wall_placement', str(wall_placement))
feature.setAttribute('point_list_opening_extrusion_area', str(point_list_opening_extrusion_area))
self.pyoutput(feature)
def close(self):
pass
def process_group(self):
pass