Reuse export_attributes for layers, groups, constraints, classifications

This commit is contained in:
Andrej730
2025-01-24 17:46:02 +05:00
parent 60f8044820
commit e3ea12a517
5 changed files with 35 additions and 63 deletions
@@ -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)
@@ -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()
@@ -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"}
+5 -12
View File
@@ -17,8 +17,9 @@
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
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"}
+3 -10
View File
@@ -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"}