Added operator to add psets to all selected objects. (#1805)

* first attempt

* Accommodate object vs non-object psets, and directly fetch applicable pset names

Co-authored-by: Dion Moult <dion@thinkmoult.com>
This commit is contained in:
Vukas Pajic
2021-10-20 05:49:02 +02:00
committed by GitHub
parent 58859ef8c3
commit 871ad1ab7f
@@ -23,12 +23,12 @@ import ifcopenshell.util.unit
import ifcopenshell.util.pset import ifcopenshell.util.pset
import ifcopenshell.util.attribute import ifcopenshell.util.attribute
import blenderbim.bim.schema import blenderbim.bim.schema
import blenderbim.tool as tool
from blenderbim.bim.ifc import IfcStore from blenderbim.bim.ifc import IfcStore
from ifcopenshell.api.pset.data import Data from ifcopenshell.api.pset.data import Data
from ifcopenshell.api.cost.data import Data as CostData from ifcopenshell.api.cost.data import Data as CostData
from blenderbim.bim.module.pset.qto_calculator import QtoCalculator from blenderbim.bim.module.pset.qto_calculator import QtoCalculator
def get_pset_props(context, obj, obj_type): def get_pset_props(context, obj, obj_type):
if obj_type == "Object": if obj_type == "Object":
obj = bpy.data.objects.get(obj) obj = bpy.data.objects.get(obj)
@@ -274,18 +274,19 @@ class AddPset(bpy.types.Operator):
def _execute(self, context): def _execute(self, context):
self.file = IfcStore.get_file() self.file = IfcStore.get_file()
props = get_pset_props(context, self.obj, self.obj_type) pset_name = get_pset_props(context, self.obj, self.obj_type).pset_name
ifc_definition_id = get_pset_obj_ifc_definition_id(context, self.obj, self.obj_type) if self.obj_type == "Object":
objects = [o.name for o in context.selected_objects]
ifcopenshell.api.run( else:
"pset.add_pset", objects = [self.obj]
self.file, for obj in objects:
**{ ifc_definition_id = get_pset_obj_ifc_definition_id(context, obj, self.obj_type)
"product": self.file.by_id(ifc_definition_id), if not ifc_definition_id:
"name": props.pset_name, continue
}, element = tool.Ifc.get().by_id(ifc_definition_id)
) if pset_name in blenderbim.bim.schema.ifc.psetqto.get_applicable_names(element.is_a(), pset_only=True):
Data.load(IfcStore.get_file(), ifc_definition_id) ifcopenshell.api.run("pset.add_pset", self.file, product=element, name=pset_name)
Data.load(IfcStore.get_file(), ifc_definition_id)
return {"FINISHED"} return {"FINISHED"}