Add support for parametric updating of cardinal points 1-9 for profile set usages

This commit is contained in:
Dion Moult
2021-06-25 17:25:26 +10:00
parent 312de694b6
commit 6e4e6a88a4
4 changed files with 174 additions and 2 deletions
@@ -426,9 +426,9 @@ class EditAssignedMaterial(bpy.types.Operator):
attributes = blenderbim.bim.helper.export_attributes(props.material_set_usage_attributes)
attributes["CardinalPoint"] = int(attributes["CardinalPoint"]) if attributes["CardinalPoint"] else None
ifcopenshell.api.run(
"material.edit_assigned_material",
"material.edit_profile_usage",
self.file,
**{"element": material_set_usage, "attributes": attributes},
**{"usage": material_set_usage, "attributes": attributes},
)
if material_set_usage.is_a("IfcMaterialLayerSetUsage"):
Data.load_layer_usages()
@@ -11,6 +11,11 @@ def load_post(*args):
ifcopenshell.api.add_post_listener(
"geometry.add_representation", "BlenderBIM.Product.GenerateBox", product.generate_box
)
ifcopenshell.api.add_post_listener(
"material.edit_profile_usage",
"BlenderBIM.Product.RegenerateProfileUsage",
product.regenerate_profile_usage,
)
IfcStore.add_element_listener(wall.element_listener)
ifcopenshell.api.add_pre_listener(
@@ -94,3 +94,24 @@ def generate_box(usecase_path, ifc_file, settings):
should_run_listeners=False,
**{"product": product, "representation": new_box}
)
def regenerate_profile_usage(usecase_path, ifc_file, settings):
elements = []
if ifc_file.schema == "IFC2X3":
for rel in ifc_file.get_inverse(settings["usage"]):
if not rel.is_a("IfcRelAssociatesMaterial"):
continue
for element in rel.RelatedObjects:
elements.append(element)
else:
for rel in settings["usage"].AssociatedTo:
for element in rel.RelatedObjects:
elements.append(element)
for element in elements:
obj = IfcStore.get_element(element.id())
if not obj:
continue
representation = ifcopenshell.util.representation.get_representation(element, "Model", "Body", "MODEL_VIEW")
if representation:
bpy.ops.bim.switch_representation(obj=obj.name, ifc_definition_id=representation.id(), should_reload=True)