Skip to content
This repository was archived by the owner on Nov 24, 2024. It is now read-only.

Commit 0506475

Browse files
committed
Feature to add building elements to construction scheduling tasks in blenderBIM and assign product to process with the ifcopenshell.api
1 parent ac092fb commit 0506475

5 files changed

Lines changed: 84 additions & 0 deletions

File tree

src/blenderbim/blenderbim/bim/module/sequence/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
operator.EnableEditingTaskTime,
4040
operator.DisableEditingTaskTime,
4141
operator.EditTaskTime,
42+
operator.AssignProduct,
4243
prop.WorkPlan,
4344
prop.BIMWorkPlanProperties,
4445
prop.Task,

src/blenderbim/blenderbim/bim/module/sequence/operator.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,7 @@ def execute(self, context):
628628
if data[attribute.name()]:
629629
new.enum_value = data[attribute.name()]
630630
props.active_task_id = self.task
631+
props.should_show_times = True
631632
return {"FINISHED"}
632633

633634

@@ -741,3 +742,23 @@ def execute(self, context):
741742
)
742743
Data.load(self.file)
743744
return {"FINISHED"}
745+
746+
747+
class AssignProduct(bpy.types.Operator):
748+
bl_idname = "bim.assign_product"
749+
bl_label = "Assign Product"
750+
task: bpy.props.IntProperty()
751+
752+
def execute(self, context):
753+
obj = bpy.context.active_object.BIMObjectProperties.ifc_definition_id
754+
props = context.scene.BIMWorkScheduleProperties
755+
self.file = IfcStore.get_file()
756+
ifcopenshell.api.run(
757+
"sequence.assign_product",
758+
self.file,
759+
relating_product = self.file.by_id(obj),
760+
related_process = self.file.by_id(self.task),
761+
)
762+
props.has_assignment = True
763+
Data.load(self.file)
764+
return {"FINISHED"}

src/blenderbim/blenderbim/bim/module/sequence/prop.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class Task(PropertyGroup):
107107
identification: StringProperty(name="Identification", update=updateTaskIdentification)
108108
ifc_definition_id: IntProperty(name="IFC Definition ID")
109109
has_children: BoolProperty(name="Has Children")
110+
has_assignment: BoolProperty(name="Has Assignement")
110111
is_expanded: BoolProperty(name="Is Expanded")
111112
level_index: IntProperty(name="Level Index")
112113
duration: StringProperty(name="Duration")

src/blenderbim/blenderbim/bim/module/sequence/ui.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,8 @@ def draw_item(self, context, layout, data, item, icon, active_data, active_propn
293293
row.operator("bim.enable_editing_task", text="", icon="GREASEPENCIL").task = item.ifc_definition_id
294294
row.operator("bim.add_task", text="", icon="ADD").task = item.ifc_definition_id
295295
row.operator("bim.remove_task", text="", icon="X").task = item.ifc_definition_id
296+
if context.selected_objects:
297+
obj = context.selected_objects[0]
298+
pass
299+
row = layout.row(align=True)
300+
row.operator("bim.assign_product", text="ADD", icon="OUTLINER_COLLECTION").task = item.ifc_definition_id
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import ifcopenshell
2+
import ifcopenshell.api
3+
4+
5+
class Usecase:
6+
def __init__(self, file, **settings):
7+
self.file = file
8+
self.settings = {
9+
"relating_product": None,
10+
"related_process": None,
11+
}
12+
for key, value in settings.items():
13+
self.settings[key] = value
14+
15+
def execute(self):
16+
referenced_by = None
17+
18+
if self.settings["relating_product"].ReferencedBy:
19+
for rel in self.settings["relating_product"].ReferencedBy:
20+
if rel.is_a("IfcRelAssignsToProduct"):
21+
referenced_by = rel
22+
23+
assignment = None
24+
for rel in self.settings["related_process"].HasAssignments:
25+
if rel.is_a('IfcRelAssignsToProduct'):
26+
assignment = rel
27+
break
28+
if referenced_by and referenced_by == assignment:
29+
return
30+
31+
if assignment:
32+
related_objects = set(assignment.RelatedObjects)
33+
related_objects.add(self.settings["relating_product"])
34+
assignment.RelatedObjects = list(related_objects)
35+
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": assignment})
36+
else:
37+
rel = self.file.create_entity(
38+
"IfcRelAssignsToProduct",
39+
**{
40+
"GlobalId": ifcopenshell.guid.new(),
41+
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
42+
"RelatingProduct": self.settings["relating_product"],
43+
"RelatedObjects": [self.settings["related_process"]],
44+
})
45+
return rel
46+
47+
if referenced_by:
48+
related_objects = list(referenced_by.RelatedObjects)
49+
related_objects.remove(self.settings["relating_product"])
50+
if related_objects:
51+
referenced_by.RelatedObjects = related_objects
52+
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": referenced_by})
53+
else:
54+
self.file.remove(referenced_by)
55+
56+
return rel

0 commit comments

Comments
 (0)