diff --git a/src/bonsai/bonsai/bim/module/attribute/operator.py b/src/bonsai/bonsai/bim/module/attribute/operator.py index 5c18604fc5..b017e222f6 100644 --- a/src/bonsai/bonsai/bim/module/attribute/operator.py +++ b/src/bonsai/bonsai/bim/module/attribute/operator.py @@ -129,14 +129,12 @@ class EditAttributes(bpy.types.Operator, tool.Ifc.Operator): def callback(attributes, prop): if prop.name in ("RefLatitude", "RefLongitude"): - if prop.is_null: - attributes[prop.name] = None - else: + if not prop.is_null: try: attributes[prop.name] = json.loads(prop.string_value) except: attributes[prop.name] = None - return True + return True attributes = bonsai.bim.helper.export_attributes(props.attributes, callback=callback) ifcopenshell.api.run("attribute.edit_attributes", self.file, product=product, attributes=attributes) diff --git a/src/bonsai/bonsai/bim/module/classification/operator.py b/src/bonsai/bonsai/bim/module/classification/operator.py index bed077d3e6..199fa2d61b 100644 --- a/src/bonsai/bonsai/bim/module/classification/operator.py +++ b/src/bonsai/bonsai/bim/module/classification/operator.py @@ -20,6 +20,7 @@ import bpy import json import ifcopenshell import ifcopenshell.api +import ifcopenshell.api.classification import ifcopenshell.util.classification import ifcopenshell.util.element import bonsai.tool as tool @@ -253,19 +254,18 @@ class EditClassification(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): props = context.scene.BIMClassificationProperties - attributes = {} - for attribute in props.classification_attributes: - if attribute.is_null: - attributes[attribute.name] = None - elif attribute.name == "ReferenceTokens": - attributes[attribute.name] = json.loads(attribute.string_value) - else: - attributes[attribute.name] = attribute.string_value - self.file = IfcStore.get_file() - ifcopenshell.api.run( - "classification.edit_classification", - self.file, - **{"classification": self.file.by_id(props.active_classification_id), "attributes": attributes}, + + def callback(attributes, prop): + if prop.name == "ReferenceTokens": + attributes[prop.name] = json.loads(prop.string_value) + return True + + attributes = bonsai.bim.helper.export_attributes(props.classification_attributes, callback=callback) + ifc_file = tool.Ifc.get() + ifcopenshell.api.classification.edit_classification( + ifc_file, + classification=ifc_file.by_id(props.active_classification_id), + attributes=attributes, ) bpy.ops.bim.disable_editing_classification() @@ -346,17 +346,11 @@ class EditClassificationReference(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): props = context.scene.BIMClassificationReferenceProperties - attributes = {} - for attribute in props.reference_attributes: - if attribute.is_null: - attributes[attribute.name] = None - else: - attributes[attribute.name] = attribute.string_value - self.file = IfcStore.get_file() - ifcopenshell.api.run( - "classification.edit_reference", - self.file, - reference=self.file.by_id(props.active_reference_id), + attributes = bonsai.bim.helper.export_attributes(props.reference_attributes) + ifc_file = tool.Ifc.get() + ifcopenshell.api.classification.edit_reference( + ifc_file, + reference=ifc_file.by_id(props.active_reference_id), attributes=attributes, ) bpy.ops.bim.disable_editing_classification_reference() diff --git a/src/bonsai/bonsai/bim/module/constraint/operator.py b/src/bonsai/bonsai/bim/module/constraint/operator.py index ccd203ee15..deed4d6335 100644 --- a/src/bonsai/bonsai/bim/module/constraint/operator.py +++ b/src/bonsai/bonsai/bim/module/constraint/operator.py @@ -19,6 +19,7 @@ import bpy import json import ifcopenshell.api +import ifcopenshell.api.constraint import ifcopenshell.util.attribute import bonsai.bim.helper import bonsai.tool as tool @@ -96,19 +97,12 @@ class EditObjective(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): props = context.scene.BIMConstraintProperties - attributes = {} - for attribute in props.constraint_attributes: - if attribute.is_null: - attributes[attribute.name] = None - elif attribute.enum_items: - attributes[attribute.name] = attribute.enum_value - else: - attributes[attribute.name] = attribute.string_value - self.file = IfcStore.get_file() - ifcopenshell.api.run( - "constraint.edit_objective", - self.file, - **{"objective": self.file.by_id(props.active_constraint_id), "attributes": attributes}, + attributes = bonsai.bim.helper.export_attributes(props.constraint_attributes) + ifc_file = tool.Ifc.get() + ifcopenshell.api.constraint.edit_objective( + ifc_file, + objective=ifc_file.by_id(props.active_constraint_id), + attributes=attributes, ) bpy.ops.bim.load_objectives() return {"FINISHED"} diff --git a/src/bonsai/bonsai/bim/module/group/operator.py b/src/bonsai/bonsai/bim/module/group/operator.py index c23c33195f..df539e76bc 100644 --- a/src/bonsai/bonsai/bim/module/group/operator.py +++ b/src/bonsai/bonsai/bim/module/group/operator.py @@ -17,8 +17,9 @@ # along with Bonsai. If not, see . import bpy -import ifcopenshell.util.attribute import ifcopenshell.api +import ifcopenshell.api.group +import ifcopenshell.util.attribute import bonsai.bim.helper import bonsai.tool as tool from bonsai.bim.ifc import IfcStore @@ -114,17 +115,9 @@ class EditGroup(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): props = context.scene.BIMGroupProperties - attributes = {} - for attribute in props.group_attributes: - if attribute.is_null: - attributes[attribute.name] = None - else: - attributes[attribute.name] = attribute.string_value - - self.file = IfcStore.get_file() - ifcopenshell.api.run( - "group.edit_group", self.file, **{"group": self.file.by_id(props.active_group_id), "attributes": attributes} - ) + attributes = bonsai.bim.helper.export_attributes(props.group_attributes) + ifc_file = tool.Ifc.get() + ifcopenshell.api.group.edit_group(ifc_file, group=ifc_file.by_id(props.active_group_id), attributes=attributes) bpy.ops.bim.load_groups() return {"FINISHED"} diff --git a/src/bonsai/bonsai/bim/module/layer/operator.py b/src/bonsai/bonsai/bim/module/layer/operator.py index a35421636a..8d73a21385 100644 --- a/src/bonsai/bonsai/bim/module/layer/operator.py +++ b/src/bonsai/bonsai/bim/module/layer/operator.py @@ -103,16 +103,9 @@ class EditPresentationLayer(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): props = context.scene.BIMLayerProperties - attributes = {} - for attribute in props.layer_attributes: - if attribute.is_null: - attributes[attribute.name] = None - else: - attributes[attribute.name] = attribute.string_value - self.file = IfcStore.get_file() - ifcopenshell.api.run( - "layer.edit_layer", self.file, **{"layer": self.file.by_id(props.active_layer_id), "attributes": attributes} - ) + attributes = bonsai.bim.helper.export_attributes(props.layer_attributes) + ifc_file = tool.Ifc.get() + ifcopenshell.api.layer.edit_layer(ifc_file, layer=ifc_file.by_id(props.active_layer_id), attributes=attributes) bpy.ops.bim.load_layers() return {"FINISHED"}