mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 02:07:36 +00:00
Feature to add building elements to construction scheduling tasks in blenderBIM and assign product to process with the ifcopenshell.api
This commit is contained in:
@@ -39,6 +39,7 @@ classes = (
|
|||||||
operator.EnableEditingTaskTime,
|
operator.EnableEditingTaskTime,
|
||||||
operator.DisableEditingTaskTime,
|
operator.DisableEditingTaskTime,
|
||||||
operator.EditTaskTime,
|
operator.EditTaskTime,
|
||||||
|
operator.AssignProduct,
|
||||||
prop.WorkPlan,
|
prop.WorkPlan,
|
||||||
prop.BIMWorkPlanProperties,
|
prop.BIMWorkPlanProperties,
|
||||||
prop.Task,
|
prop.Task,
|
||||||
|
|||||||
@@ -628,6 +628,7 @@ class EnableEditingTask(bpy.types.Operator):
|
|||||||
if data[attribute.name()]:
|
if data[attribute.name()]:
|
||||||
new.enum_value = data[attribute.name()]
|
new.enum_value = data[attribute.name()]
|
||||||
props.active_task_id = self.task
|
props.active_task_id = self.task
|
||||||
|
props.should_show_times = True
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
@@ -741,3 +742,23 @@ class UnassignSuccessor(bpy.types.Operator):
|
|||||||
)
|
)
|
||||||
Data.load(self.file)
|
Data.load(self.file)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
class AssignProduct(bpy.types.Operator):
|
||||||
|
bl_idname = "bim.assign_product"
|
||||||
|
bl_label = "Assign Product"
|
||||||
|
task: bpy.props.IntProperty()
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
obj = bpy.context.active_object.BIMObjectProperties.ifc_definition_id
|
||||||
|
props = context.scene.BIMWorkScheduleProperties
|
||||||
|
self.file = IfcStore.get_file()
|
||||||
|
ifcopenshell.api.run(
|
||||||
|
"sequence.assign_product",
|
||||||
|
self.file,
|
||||||
|
relating_product = self.file.by_id(obj),
|
||||||
|
related_process = self.file.by_id(self.task),
|
||||||
|
)
|
||||||
|
props.has_assignment = True
|
||||||
|
Data.load(self.file)
|
||||||
|
return {"FINISHED"}
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ class Task(PropertyGroup):
|
|||||||
identification: StringProperty(name="Identification", update=updateTaskIdentification)
|
identification: StringProperty(name="Identification", update=updateTaskIdentification)
|
||||||
ifc_definition_id: IntProperty(name="IFC Definition ID")
|
ifc_definition_id: IntProperty(name="IFC Definition ID")
|
||||||
has_children: BoolProperty(name="Has Children")
|
has_children: BoolProperty(name="Has Children")
|
||||||
|
has_assignment: BoolProperty(name="Has Assignement")
|
||||||
is_expanded: BoolProperty(name="Is Expanded")
|
is_expanded: BoolProperty(name="Is Expanded")
|
||||||
level_index: IntProperty(name="Level Index")
|
level_index: IntProperty(name="Level Index")
|
||||||
duration: StringProperty(name="Duration")
|
duration: StringProperty(name="Duration")
|
||||||
|
|||||||
@@ -293,3 +293,8 @@ class BIM_UL_tasks(UIList):
|
|||||||
row.operator("bim.enable_editing_task", text="", icon="GREASEPENCIL").task = item.ifc_definition_id
|
row.operator("bim.enable_editing_task", text="", icon="GREASEPENCIL").task = item.ifc_definition_id
|
||||||
row.operator("bim.add_task", text="", icon="ADD").task = item.ifc_definition_id
|
row.operator("bim.add_task", text="", icon="ADD").task = item.ifc_definition_id
|
||||||
row.operator("bim.remove_task", text="", icon="X").task = item.ifc_definition_id
|
row.operator("bim.remove_task", text="", icon="X").task = item.ifc_definition_id
|
||||||
|
if context.selected_objects:
|
||||||
|
obj = context.selected_objects[0]
|
||||||
|
pass
|
||||||
|
row = layout.row(align=True)
|
||||||
|
row.operator("bim.assign_product", text="ADD", icon="OUTLINER_COLLECTION").task = item.ifc_definition_id
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
import ifcopenshell
|
||||||
|
import ifcopenshell.api
|
||||||
|
|
||||||
|
|
||||||
|
class Usecase:
|
||||||
|
def __init__(self, file, **settings):
|
||||||
|
self.file = file
|
||||||
|
self.settings = {
|
||||||
|
"relating_product": None,
|
||||||
|
"related_process": None,
|
||||||
|
}
|
||||||
|
for key, value in settings.items():
|
||||||
|
self.settings[key] = value
|
||||||
|
|
||||||
|
def execute(self):
|
||||||
|
referenced_by = None
|
||||||
|
|
||||||
|
if self.settings["relating_product"].ReferencedBy:
|
||||||
|
for rel in self.settings["relating_product"].ReferencedBy:
|
||||||
|
if rel.is_a("IfcRelAssignsToProduct"):
|
||||||
|
referenced_by = rel
|
||||||
|
|
||||||
|
assignment = None
|
||||||
|
for rel in self.settings["related_process"].HasAssignments:
|
||||||
|
if rel.is_a('IfcRelAssignsToProduct'):
|
||||||
|
assignment = rel
|
||||||
|
break
|
||||||
|
if referenced_by and referenced_by == assignment:
|
||||||
|
return
|
||||||
|
|
||||||
|
if assignment:
|
||||||
|
related_objects = set(assignment.RelatedObjects)
|
||||||
|
related_objects.add(self.settings["relating_product"])
|
||||||
|
assignment.RelatedObjects = list(related_objects)
|
||||||
|
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": assignment})
|
||||||
|
else:
|
||||||
|
rel = self.file.create_entity(
|
||||||
|
"IfcRelAssignsToProduct",
|
||||||
|
**{
|
||||||
|
"GlobalId": ifcopenshell.guid.new(),
|
||||||
|
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
|
||||||
|
"RelatingProduct": self.settings["relating_product"],
|
||||||
|
"RelatedObjects": [self.settings["related_process"]],
|
||||||
|
})
|
||||||
|
return rel
|
||||||
|
|
||||||
|
if referenced_by:
|
||||||
|
related_objects = list(referenced_by.RelatedObjects)
|
||||||
|
related_objects.remove(self.settings["relating_product"])
|
||||||
|
if related_objects:
|
||||||
|
referenced_by.RelatedObjects = related_objects
|
||||||
|
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": referenced_by})
|
||||||
|
else:
|
||||||
|
self.file.remove(referenced_by)
|
||||||
|
|
||||||
|
return rel
|
||||||
Reference in New Issue
Block a user