Assign and Unassign resources to scene objects in BlenderBIM

This commit is contained in:
bosonprojets
2021-04-25 23:25:05 +00:00
parent 7041d17c16
commit cdd456bede
4 changed files with 59 additions and 3 deletions
@@ -12,6 +12,8 @@ classes = (
operator.LoadResourceProperties,
operator.ExpandResource,
operator.ContractResource,
operator.AssignResource,
operator.UnAssignResource,
prop.Resource,
prop.BIMResourceProperties,
prop.BIMResourceTreeProperties,
@@ -197,3 +197,47 @@ class ContractResource(bpy.types.Operator):
Data.load(self.file)
bpy.ops.bim.load_resources()
return {"FINISHED"}
class AssignResource(bpy.types.Operator):
bl_idname = "bim.assign_resource"
bl_label = "Assign Resource"
resource: bpy.props.IntProperty()
related_object: bpy.props.StringProperty()
def execute(self, context):
related_objects = (
[bpy.data.objects.get(self.related_object)] if self.related_object else bpy.context.selected_objects
)
for related_object in related_objects:
self.file = IfcStore.get_file()
ifcopenshell.api.run(
"resource.assign_resource",
self.file,
relating_resource=self.file.by_id(self.resource),
related_object=self.file.by_id(related_object.BIMObjectProperties.ifc_definition_id),
)
Data.load(self.file)
return {"FINISHED"}
class UnAssignResource(bpy.types.Operator):
bl_idname = "bim.unassign_resource"
bl_label = "Unassign Resource"
resource: bpy.props.IntProperty()
related_object: bpy.props.StringProperty()
def execute(self, context):
related_objects = (
[bpy.data.objects.get(self.related_object)] if self.related_object else bpy.context.selected_objects
)
for related_object in related_objects:
self.file = IfcStore.get_file()
ifcopenshell.api.run(
"resource.unassign_resource",
self.file,
relating_resource=self.file.by_id(self.resource),
related_object=self.file.by_id(related_object.BIMObjectProperties.ifc_definition_id),
)
Data.load(self.file)
return {"FINISHED"}
@@ -33,7 +33,7 @@ class BIM_PT_resources(Panel):
return
row = self.layout.row(align=True)
op = row.operator("bim.add_resource", text="Add SubContract", icon="FILE_TICK")
op = row.operator("bim.add_resource", text="Add SubContract", icon="TEXT")
op.ifc_class = "IfcSubContractResource"
op.resource = 0
op = row.operator("bim.add_resource", text="Add Crew", icon="COMMUNITY")
@@ -88,7 +88,7 @@ class BIM_UL_resources(UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
resource = Data.resources[item.ifc_definition_id]
icon_map = {
"IfcSubContractResource": "FILE_TICK",
"IfcSubContractResource": "TEXT",
"IfcCrewResource": "COMMUNITY",
"IfcConstructionEquipmentResource": "TOOL_SETTINGS",
"IfcLaborResource": "OUTLINER_OB_ARMATURE",
@@ -113,6 +113,16 @@ class BIM_UL_resources(UIList):
row.label(text="", icon="DOT")
row.prop(item, "name", emboss=False, text="", icon=icon_map[resource["type"]])
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"]:
op = row.operator("bim.unassign_resource", text="", icon="KEYFRAME_HLT", emboss=False)
op.resource = item.ifc_definition_id
else:
op = row.operator("bim.assign_resource", text="", icon="KEYFRAME", emboss=False)
op.resource = item.ifc_definition_id
if props.active_resource_id == item.ifc_definition_id:
row.operator("bim.edit_resource", text="", icon="CHECKMARK")
row.operator("bim.disable_editing_resource", text="", icon="CANCEL")
@@ -37,7 +37,7 @@ class Usecase:
"GlobalId": ifcopenshell.guid.new(),
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
"RelatedObjects": [self.settings["related_object"]],
"RelatingProduct": self.settings["relating_resource"],
"RelatingResource": self.settings["relating_resource"],
}
)
return resource_of