mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
Reuse export_attributes for layers, groups, constraints, classifications
This commit is contained in:
@@ -129,14 +129,12 @@ class EditAttributes(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
|
|
||||||
def callback(attributes, prop):
|
def callback(attributes, prop):
|
||||||
if prop.name in ("RefLatitude", "RefLongitude"):
|
if prop.name in ("RefLatitude", "RefLongitude"):
|
||||||
if prop.is_null:
|
if not prop.is_null:
|
||||||
attributes[prop.name] = None
|
|
||||||
else:
|
|
||||||
try:
|
try:
|
||||||
attributes[prop.name] = json.loads(prop.string_value)
|
attributes[prop.name] = json.loads(prop.string_value)
|
||||||
except:
|
except:
|
||||||
attributes[prop.name] = None
|
attributes[prop.name] = None
|
||||||
return True
|
return True
|
||||||
|
|
||||||
attributes = bonsai.bim.helper.export_attributes(props.attributes, callback=callback)
|
attributes = bonsai.bim.helper.export_attributes(props.attributes, callback=callback)
|
||||||
ifcopenshell.api.run("attribute.edit_attributes", self.file, product=product, attributes=attributes)
|
ifcopenshell.api.run("attribute.edit_attributes", self.file, product=product, attributes=attributes)
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import bpy
|
|||||||
import json
|
import json
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import ifcopenshell.api
|
import ifcopenshell.api
|
||||||
|
import ifcopenshell.api.classification
|
||||||
import ifcopenshell.util.classification
|
import ifcopenshell.util.classification
|
||||||
import ifcopenshell.util.element
|
import ifcopenshell.util.element
|
||||||
import bonsai.tool as tool
|
import bonsai.tool as tool
|
||||||
@@ -253,19 +254,18 @@ class EditClassification(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
props = context.scene.BIMClassificationProperties
|
props = context.scene.BIMClassificationProperties
|
||||||
attributes = {}
|
|
||||||
for attribute in props.classification_attributes:
|
def callback(attributes, prop):
|
||||||
if attribute.is_null:
|
if prop.name == "ReferenceTokens":
|
||||||
attributes[attribute.name] = None
|
attributes[prop.name] = json.loads(prop.string_value)
|
||||||
elif attribute.name == "ReferenceTokens":
|
return True
|
||||||
attributes[attribute.name] = json.loads(attribute.string_value)
|
|
||||||
else:
|
attributes = bonsai.bim.helper.export_attributes(props.classification_attributes, callback=callback)
|
||||||
attributes[attribute.name] = attribute.string_value
|
ifc_file = tool.Ifc.get()
|
||||||
self.file = IfcStore.get_file()
|
ifcopenshell.api.classification.edit_classification(
|
||||||
ifcopenshell.api.run(
|
ifc_file,
|
||||||
"classification.edit_classification",
|
classification=ifc_file.by_id(props.active_classification_id),
|
||||||
self.file,
|
attributes=attributes,
|
||||||
**{"classification": self.file.by_id(props.active_classification_id), "attributes": attributes},
|
|
||||||
)
|
)
|
||||||
bpy.ops.bim.disable_editing_classification()
|
bpy.ops.bim.disable_editing_classification()
|
||||||
|
|
||||||
@@ -346,17 +346,11 @@ class EditClassificationReference(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
props = context.scene.BIMClassificationReferenceProperties
|
props = context.scene.BIMClassificationReferenceProperties
|
||||||
attributes = {}
|
attributes = bonsai.bim.helper.export_attributes(props.reference_attributes)
|
||||||
for attribute in props.reference_attributes:
|
ifc_file = tool.Ifc.get()
|
||||||
if attribute.is_null:
|
ifcopenshell.api.classification.edit_reference(
|
||||||
attributes[attribute.name] = None
|
ifc_file,
|
||||||
else:
|
reference=ifc_file.by_id(props.active_reference_id),
|
||||||
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=attributes,
|
attributes=attributes,
|
||||||
)
|
)
|
||||||
bpy.ops.bim.disable_editing_classification_reference()
|
bpy.ops.bim.disable_editing_classification_reference()
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
import bpy
|
import bpy
|
||||||
import json
|
import json
|
||||||
import ifcopenshell.api
|
import ifcopenshell.api
|
||||||
|
import ifcopenshell.api.constraint
|
||||||
import ifcopenshell.util.attribute
|
import ifcopenshell.util.attribute
|
||||||
import bonsai.bim.helper
|
import bonsai.bim.helper
|
||||||
import bonsai.tool as tool
|
import bonsai.tool as tool
|
||||||
@@ -96,19 +97,12 @@ class EditObjective(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
props = context.scene.BIMConstraintProperties
|
props = context.scene.BIMConstraintProperties
|
||||||
attributes = {}
|
attributes = bonsai.bim.helper.export_attributes(props.constraint_attributes)
|
||||||
for attribute in props.constraint_attributes:
|
ifc_file = tool.Ifc.get()
|
||||||
if attribute.is_null:
|
ifcopenshell.api.constraint.edit_objective(
|
||||||
attributes[attribute.name] = None
|
ifc_file,
|
||||||
elif attribute.enum_items:
|
objective=ifc_file.by_id(props.active_constraint_id),
|
||||||
attributes[attribute.name] = attribute.enum_value
|
attributes=attributes,
|
||||||
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},
|
|
||||||
)
|
)
|
||||||
bpy.ops.bim.load_objectives()
|
bpy.ops.bim.load_objectives()
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|||||||
@@ -17,8 +17,9 @@
|
|||||||
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
|
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
import ifcopenshell.util.attribute
|
|
||||||
import ifcopenshell.api
|
import ifcopenshell.api
|
||||||
|
import ifcopenshell.api.group
|
||||||
|
import ifcopenshell.util.attribute
|
||||||
import bonsai.bim.helper
|
import bonsai.bim.helper
|
||||||
import bonsai.tool as tool
|
import bonsai.tool as tool
|
||||||
from bonsai.bim.ifc import IfcStore
|
from bonsai.bim.ifc import IfcStore
|
||||||
@@ -114,17 +115,9 @@ class EditGroup(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
props = context.scene.BIMGroupProperties
|
props = context.scene.BIMGroupProperties
|
||||||
attributes = {}
|
attributes = bonsai.bim.helper.export_attributes(props.group_attributes)
|
||||||
for attribute in props.group_attributes:
|
ifc_file = tool.Ifc.get()
|
||||||
if attribute.is_null:
|
ifcopenshell.api.group.edit_group(ifc_file, group=ifc_file.by_id(props.active_group_id), attributes=attributes)
|
||||||
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}
|
|
||||||
)
|
|
||||||
bpy.ops.bim.load_groups()
|
bpy.ops.bim.load_groups()
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|||||||
@@ -103,16 +103,9 @@ class EditPresentationLayer(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
props = context.scene.BIMLayerProperties
|
props = context.scene.BIMLayerProperties
|
||||||
attributes = {}
|
attributes = bonsai.bim.helper.export_attributes(props.layer_attributes)
|
||||||
for attribute in props.layer_attributes:
|
ifc_file = tool.Ifc.get()
|
||||||
if attribute.is_null:
|
ifcopenshell.api.layer.edit_layer(ifc_file, layer=ifc_file.by_id(props.active_layer_id), attributes=attributes)
|
||||||
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}
|
|
||||||
)
|
|
||||||
bpy.ops.bim.load_layers()
|
bpy.ops.bim.load_layers()
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user