Minor code review to assign / unassign resource products

This commit is contained in:
Dion Moult
2021-04-26 09:38:45 +10:00
parent cdd456bede
commit f88ac5de62
5 changed files with 10 additions and 8 deletions
@@ -13,7 +13,7 @@ classes = (
operator.ExpandResource,
operator.ContractResource,
operator.AssignResource,
operator.UnAssignResource,
operator.UnassignResource,
prop.Resource,
prop.BIMResourceProperties,
prop.BIMResourceTreeProperties,
@@ -30,10 +30,10 @@ class LoadResources(bpy.types.Operator):
new.ifc_definition_id = related_object_id
new.is_expanded = related_object_id not in self.contracted_resources
new.level_index = level_index
if resource["RelatedObjects"]:
if resource["IsNestedBy"]:
new.has_children = True
if new.is_expanded:
for related_object_id in resource["RelatedObjects"]:
for related_object_id in resource["IsNestedBy"]:
self.create_new_resource_li(related_object_id, level_index + 1)
return {"FINISHED"}
@@ -221,7 +221,7 @@ class AssignResource(bpy.types.Operator):
return {"FINISHED"}
class UnAssignResource(bpy.types.Operator):
class UnassignResource(bpy.types.Operator):
bl_idname = "bim.unassign_resource"
bl_label = "Unassign Resource"
resource: bpy.props.IntProperty()
@@ -116,7 +116,7 @@ class BIM_UL_resources(UIList):
if context.active_object:
oprops = context.active_object.BIMObjectProperties
row = layout.row(align=True)
if oprops.ifc_definition_id in Data.resources[item.ifc_definition_id]["RelatedObjects"]:
if oprops.ifc_definition_id in Data.resources[item.ifc_definition_id]["ResourceOf"]:
op = row.operator("bim.unassign_resource", text="", icon="KEYFRAME_HLT", emboss=False)
op.resource = item.ifc_definition_id
else:
@@ -12,9 +12,12 @@ class Data:
for resource in file.by_type("IfcResource"):
data = resource.get_info()
del data["OwnerHistory"]
data["RelatedObjects"] = []
data["IsNestedBy"] = []
for rel in resource.IsNestedBy:
[data["RelatedObjects"].append(o.id()) for o in rel.RelatedObjects]
[data["IsNestedBy"].append(o.id()) for o in rel.RelatedObjects]
data["ResourceOf"] = []
for rel in resource.ResourceOf:
[data["ResourceOf"].append(o.id()) for o in rel.RelatedObjects]
data["HasContext"] = resource.HasContext[0].RelatingContext.id() if resource.HasContext else None
cls.resources[resource.id()] = data
cls.is_loaded=True
@@ -1,4 +1,3 @@
import ifcopenshell
import ifcopenshell.api