mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-18 22:33:33 +00:00
Assign and Unassign resources to scene objects in BlenderBIM
This commit is contained in:
@@ -12,6 +12,8 @@ classes = (
|
|||||||
operator.LoadResourceProperties,
|
operator.LoadResourceProperties,
|
||||||
operator.ExpandResource,
|
operator.ExpandResource,
|
||||||
operator.ContractResource,
|
operator.ContractResource,
|
||||||
|
operator.AssignResource,
|
||||||
|
operator.UnAssignResource,
|
||||||
prop.Resource,
|
prop.Resource,
|
||||||
prop.BIMResourceProperties,
|
prop.BIMResourceProperties,
|
||||||
prop.BIMResourceTreeProperties,
|
prop.BIMResourceTreeProperties,
|
||||||
|
|||||||
@@ -197,3 +197,47 @@ class ContractResource(bpy.types.Operator):
|
|||||||
Data.load(self.file)
|
Data.load(self.file)
|
||||||
bpy.ops.bim.load_resources()
|
bpy.ops.bim.load_resources()
|
||||||
return {"FINISHED"}
|
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
|
return
|
||||||
|
|
||||||
row = self.layout.row(align=True)
|
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.ifc_class = "IfcSubContractResource"
|
||||||
op.resource = 0
|
op.resource = 0
|
||||||
op = row.operator("bim.add_resource", text="Add Crew", icon="COMMUNITY")
|
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):
|
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
|
||||||
resource = Data.resources[item.ifc_definition_id]
|
resource = Data.resources[item.ifc_definition_id]
|
||||||
icon_map = {
|
icon_map = {
|
||||||
"IfcSubContractResource": "FILE_TICK",
|
"IfcSubContractResource": "TEXT",
|
||||||
"IfcCrewResource": "COMMUNITY",
|
"IfcCrewResource": "COMMUNITY",
|
||||||
"IfcConstructionEquipmentResource": "TOOL_SETTINGS",
|
"IfcConstructionEquipmentResource": "TOOL_SETTINGS",
|
||||||
"IfcLaborResource": "OUTLINER_OB_ARMATURE",
|
"IfcLaborResource": "OUTLINER_OB_ARMATURE",
|
||||||
@@ -113,6 +113,16 @@ class BIM_UL_resources(UIList):
|
|||||||
row.label(text="", icon="DOT")
|
row.label(text="", icon="DOT")
|
||||||
row.prop(item, "name", emboss=False, text="", icon=icon_map[resource["type"]])
|
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:
|
if props.active_resource_id == item.ifc_definition_id:
|
||||||
row.operator("bim.edit_resource", text="", icon="CHECKMARK")
|
row.operator("bim.edit_resource", text="", icon="CHECKMARK")
|
||||||
row.operator("bim.disable_editing_resource", text="", icon="CANCEL")
|
row.operator("bim.disable_editing_resource", text="", icon="CANCEL")
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class Usecase:
|
|||||||
"GlobalId": ifcopenshell.guid.new(),
|
"GlobalId": ifcopenshell.guid.new(),
|
||||||
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
|
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
|
||||||
"RelatedObjects": [self.settings["related_object"]],
|
"RelatedObjects": [self.settings["related_object"]],
|
||||||
"RelatingProduct": self.settings["relating_resource"],
|
"RelatingResource": self.settings["relating_resource"],
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return resource_of
|
return resource_of
|
||||||
|
|||||||
Reference in New Issue
Block a user