mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 17:58:20 +00:00
You can now add and remove work plans with a new UI. Thanks @bosonprojets and @jesusbill!
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.util.date
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file, **settings):
|
||||
self.file = file
|
||||
self.settings = {"name": None, "predefined_type": "NOTDEFINED", "start_time": datetime.now()}
|
||||
for key, value in settings.items():
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
work_plan = ifcopenshell.api.run(
|
||||
"root.create_entity",
|
||||
self.file,
|
||||
ifc_class="IfcWorkPlan",
|
||||
predefined_type=self.settings["predefined_type"],
|
||||
name=self.settings["name"],
|
||||
)
|
||||
work_plan.CreationDate = ifcopenshell.util.date.datetime2ifc(datetime.now(), "IfcDateTime")
|
||||
person = ifcopenshell.api.owner.settings.get_person(self.file)
|
||||
if person:
|
||||
work_plan.Creators = [person]
|
||||
work_plan.StartTime = ifcopenshell.util.date.datetime2ifc(self.settings["start_time"], "IfcDateTime")
|
||||
|
||||
context = self.file.by_type("IfcContext")[0]
|
||||
if context.Declares:
|
||||
rel_declares = context.Declares[0]
|
||||
ifcopenshell.api.run("owner.update_owner_history", self.file, element=rel_declares)
|
||||
else:
|
||||
rel_declares = self.file.create_entity("IfcRelDeclares", **{
|
||||
"GlobalId": ifcopenshell.guid.new(),
|
||||
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
|
||||
"RelatingContext": context
|
||||
})
|
||||
|
||||
related_definitions = list(rel_declares.RelatedDefinitions or [])
|
||||
related_definitions.append(work_plan)
|
||||
rel_declares.RelatedDefinitions = related_definitions
|
||||
|
||||
return work_plan
|
||||
Reference in New Issue
Block a user