From a91242371b34d6d629335d706002c0376857b19d Mon Sep 17 00:00:00 2001 From: Gorgious Date: Wed, 25 Aug 2021 15:14:42 +0200 Subject: [PATCH] Revert changes to geometry operator --- .../bim/module/geometry/operator.py | 150 +++++++++--------- 1 file changed, 75 insertions(+), 75 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/geometry/operator.py b/src/blenderbim/blenderbim/bim/module/geometry/operator.py index 4ad66ebda0..4af285fa94 100644 --- a/src/blenderbim/blenderbim/bim/module/geometry/operator.py +++ b/src/blenderbim/blenderbim/bim/module/geometry/operator.py @@ -88,87 +88,87 @@ class AddRepresentation(bpy.types.Operator): return IfcStore.execute_ifc_operator(self, context) def _execute(self, context): + obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object self.file = IfcStore.get_file() + + bpy.ops.bim.edit_object_placement(obj=obj.name) + + if not obj.data: + return {"FINISHED"} + + product = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id) + + context_id = self.context_id or int(context.scene.BIMProperties.contexts) + context_of_items = self.file.by_id(context_id) + gprop = context.scene.BIMGeoreferenceProperties - objs = [bpy.data.objects.get(self.obj)] if self.obj else context.selected_objects - for obj in objs: - obj_id = obj.BIMObjectProperties.ifc_definition_id - if not obj_id: - continue - bpy.ops.bim.edit_object_placement(obj=obj.name) - if not obj.data or not hasattr(obj.data, "polygons"): - continue - - product = self.file.by_id(obj_id) - - context_id = self.context_id or int(context.scene.BIMProperties.contexts) - context_of_items = self.file.by_id(context_id) - coordinate_offset = None - if gprop.has_blender_offset and obj.BIMObjectProperties.blender_offset_type == "CARTESIAN_POINT": - coordinate_offset = Vector( - ( - float(gprop.blender_eastings), - float(gprop.blender_northings), - float(gprop.blender_orthogonal_height), - ) + coordinate_offset = None + if gprop.has_blender_offset and obj.BIMObjectProperties.blender_offset_type == "CARTESIAN_POINT": + coordinate_offset = Vector( + ( + float(gprop.blender_eastings), + float(gprop.blender_northings), + float(gprop.blender_orthogonal_height), ) - - representation_data = { - "context": context_of_items, - "blender_object": obj, - "geometry": obj.data, - "coordinate_offset": coordinate_offset, - "total_items": max(1, len(obj.material_slots)), - "should_force_faceted_brep": context.scene.BIMGeometryProperties.should_force_faceted_brep, - "should_force_triangulation": context.scene.BIMGeometryProperties.should_force_triangulation, - "ifc_representation_class": self.ifc_representation_class, - "profile_set_usage": self.file.by_id(self.profile_set_usage) if self.profile_set_usage else None, - } - - result = ifcopenshell.api.run("geometry.add_representation", self.file, **representation_data) - - if not result: - print("Failed to write shape representation") - continue - - [ - bpy.ops.bim.add_style(material=s.material.name) - for s in obj.material_slots - if s.material and not s.material.BIMMaterialProperties.ifc_style_id - ] - - if obj.type == "MESH" and len(obj.data.polygons): - ifcopenshell.api.run( - "style.assign_representation_styles", - self.file, - **{ - "shape_representation": result, - "styles": [ - self.file.by_id(s.material.BIMMaterialProperties.ifc_style_id) - for s in obj.material_slots - if s.material - ], - "should_use_presentation_style_assignment": context.scene.BIMGeometryProperties.should_use_presentation_style_assignment, - }, - ) - ifcopenshell.api.run( - "geometry.assign_representation", self.file, **{"product": product, "representation": result} ) - mesh = obj.data.copy() - mesh.name = "{}/{}".format(context_id, result.id()) - mesh.BIMMeshProperties.ifc_definition_id = int(result.id()) - obj.data = mesh - Data.load(self.file, obj_id) + representation_data = { + "context": context_of_items, + "blender_object": obj, + "geometry": obj.data, + "coordinate_offset": coordinate_offset, + "total_items": max(1, len(obj.material_slots)), + "should_force_faceted_brep": context.scene.BIMGeometryProperties.should_force_faceted_brep, + "should_force_triangulation": context.scene.BIMGeometryProperties.should_force_triangulation, + "ifc_representation_class": self.ifc_representation_class, + "profile_set_usage": self.file.by_id(self.profile_set_usage) if self.profile_set_usage else None, + } - if product.is_a("IfcTypeProduct"): - if self.file.schema == "IFC2X3": - types = product.ObjectTypeOf - else: - types = product.Types - if types: - for element in types[0].RelatedObjects: - Data.load(self.file, element.id()) + result = ifcopenshell.api.run("geometry.add_representation", self.file, **representation_data) + + if not result: + print("Failed to write shape representation") + return {"FINISHED"} + + [ + bpy.ops.bim.add_style(material=s.material.name) + for s in obj.material_slots + if s.material and not s.material.BIMMaterialProperties.ifc_style_id + ] + + if isinstance(obj.data, bpy.types.Mesh) and len(obj.data.polygons): + ifcopenshell.api.run( + "style.assign_representation_styles", + self.file, + **{ + "shape_representation": result, + "styles": [ + self.file.by_id(s.material.BIMMaterialProperties.ifc_style_id) + for s in obj.material_slots + if s.material + ], + "should_use_presentation_style_assignment": context.scene.BIMGeometryProperties.should_use_presentation_style_assignment, + }, + ) + ifcopenshell.api.run( + "geometry.assign_representation", self.file, **{"product": product, "representation": result} + ) + + existing_mesh = obj.data + mesh = obj.data.copy() + mesh.name = "{}/{}".format(context_id, result.id()) + mesh.BIMMeshProperties.ifc_definition_id = int(result.id()) + obj.data = mesh + Data.load(IfcStore.get_file(), obj.BIMObjectProperties.ifc_definition_id) + + if product.is_a("IfcTypeProduct"): + if self.file.schema == "IFC2X3": + types = product.ObjectTypeOf + else: + types = product.Types + if types: + for element in types[0].RelatedObjects: + Data.load(IfcStore.get_file(), element.id()) return {"FINISHED"}