Refactor representation creation into its own function

This commit is contained in:
Dion Moult
2019-09-01 09:44:06 +10:00
parent 64b23393a0
commit 7c2d640106
+13 -11
View File
@@ -162,8 +162,20 @@ class IfcExporter():
def create_products(self): def create_products(self):
for product in self.ifc_parser.products: for product in self.ifc_parser.products:
object = product['raw'] object = product['raw']
placement_rel_to = self.ifc_parser.spatial_structure_elements[product['relating_structure']]['ifc'].ObjectPlacement
placement = self.file.createIfcLocalPlacement(placement_rel_to,
self.file.createIfcAxis2Placement3D(
self.file.createIfcCartesianPoint(
(object.location.x, object.location.y, object.location.z))))
representation = self.create_representation(object)
product['ifc'] = self.file.createIfcBuildingElementProxy(
ifcopenshell.guid.new(),
self.owner_history, object.name, None, None, placement, representation, None, None)
def create_representation(self, object):
ifc_vertices = [] ifc_vertices = []
ifc_faces = [] ifc_faces = []
for vertice in object.data.vertices: for vertice in object.data.vertices:
ifc_vertices.append( ifc_vertices.append(
self.file.createIfcCartesianPoint((vertice.co.x, vertice.co.y, vertice.co.z))) self.file.createIfcCartesianPoint((vertice.co.x, vertice.co.y, vertice.co.z)))
@@ -173,21 +185,11 @@ class IfcExporter():
self.file.createIfcPolyLoop([ifc_vertices[vertice] for vertice in polygon.vertices]), self.file.createIfcPolyLoop([ifc_vertices[vertice] for vertice in polygon.vertices]),
True)])) True)]))
representation = self.file.createIfcProductDefinitionShape(None, None, return self.file.createIfcProductDefinitionShape(None, None,
[self.file.createIfcShapeRepresentation( [self.file.createIfcShapeRepresentation(
self.ifc_rep_subcontext, 'Body', 'Brep', self.ifc_rep_subcontext, 'Body', 'Brep',
[self.file.createIfcFacetedBrep(self.file.createIfcClosedShell(ifc_faces))])]) [self.file.createIfcFacetedBrep(self.file.createIfcClosedShell(ifc_faces))])])
placement_rel_to = self.ifc_parser.spatial_structure_elements[product['relating_structure']]['ifc'].ObjectPlacement
placement = self.file.createIfcLocalPlacement(placement_rel_to,
self.file.createIfcAxis2Placement3D(
self.file.createIfcCartesianPoint(
(object.location.x, object.location.y, object.location.z))))
product['ifc'] = self.file.createIfcBuildingElementProxy(
ifcopenshell.guid.new(),
self.owner_history, object.name, None, None, placement, representation, None, None)
def relate_elements_to_spatial_structures(self): def relate_elements_to_spatial_structures(self):
for relating_structure, related_elements in self.ifc_parser.rel_contained_in_spatial_structure.items(): for relating_structure, related_elements in self.ifc_parser.rel_contained_in_spatial_structure.items():
self.file.createIfcRelContainedInSpatialStructure( self.file.createIfcRelContainedInSpatialStructure(