Skip to content

Commit

Permalink
Fix #4547. Handle both null inherited predefined types and disable ed…
Browse files Browse the repository at this point in the history
…iting predefined types on occurrences which inherit from a type.
  • Loading branch information
Moult committed Apr 15, 2024
1 parent 8a62558 commit acf6628
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
17 changes: 13 additions & 4 deletions src/blenderbim/blenderbim/bim/module/attribute/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,18 @@ def execute(self, context):
obj = bpy.data.objects.get(self.obj)
elif self.obj_type == "Material":
obj = bpy.data.materials.get(self.obj)
oprops = obj.BIMObjectProperties
props = obj.BIMAttributeProperties
props.attributes.clear()

element = tool.Ifc.get_entity(obj)
has_inherited_predefined_type = False
if not element.is_a("IfcTypeObject") and (element_type := ifcopenshell.util.element.get_type(element)):
# Allow for None due to https://github.com/buildingSMART/IFC4.3.x-development/issues/818
has_inherited_predefined_type = ifcopenshell.util.element.get_predefined_type(element_type) not in (
"NOTDEFINED",
None,
)

def callback(name, prop, data):
if name in ("RefLatitude", "RefLongitude"):
new = props.attributes.add()
Expand All @@ -62,10 +70,11 @@ def callback(name, prop, data):
new.string_value = "" if new.is_null else json.dumps(data[name])
blenderbim.bim.helper.add_attribute_description(new)
new.description += " The degrees, minutes and seconds should follow this format : [12,34,56]"
if name in ("PredefinedType", "ObjectType") and has_inherited_predefined_type:
props.attributes.remove(len(props.attributes) - 1)
return True

blenderbim.bim.helper.import_attributes2(
tool.Ifc.get().by_id(oprops.ifc_definition_id), props.attributes, callback=callback
)
blenderbim.bim.helper.import_attributes2(element, props.attributes, callback=callback)
props.is_editing_attributes = True
return {"FINISHED"}

Expand Down
3 changes: 2 additions & 1 deletion src/blenderbim/blenderbim/bim/module/root/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ def has_inherited_predefined_type(cls):
if not element:
return
if element_type := ifcopenshell.util.element.get_type(element):
return ifcopenshell.util.element.get_predefined_type(element_type) != "NOTDEFINED"
# Allow for None due to https://github.com/buildingSMART/IFC4.3.x-development/issues/818
return ifcopenshell.util.element.get_predefined_type(element_type) not in ("NOTDEFINED", None)
return False

@classmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def execute(self):
self.settings["product"].PredefinedType = "USERDEFINED"
elif hasattr(self.settings["product"], "ObjectType"):
relating_type = ifcopenshell.util.element.get_type(self.settings["product"])
if relating_type and relating_type.PredefinedType != "NOTDEFINED":
# Allow for None due to https://github.com/buildingSMART/IFC4.3.x-development/issues/818
if relating_type and relating_type.PredefinedType not in ("NOTDEFINED", None):
self.settings["product"].ObjectType = None
self.settings["product"].PredefinedType = None
elif (
Expand Down

0 comments on commit acf6628

Please sign in to comment.