refactor pset operator

This commit is contained in:
Sigma Dimensions
2023-03-01 15:37:19 +01:00
parent fb3023bb79
commit cf2ad43ed7
4 changed files with 99 additions and 4 deletions
+15
View File
@@ -28,3 +28,18 @@ def copy_property_to_selection(ifc, pset, is_pset=True, obj=None, pset_name=None
ifc.run("pset.edit_pset", pset=ifc_pset, properties={prop_name: prop_value})
else:
ifc.run("pset.edit_qto", qto=ifc_pset, properties={prop_name: prop_value})
def add_pset(ifc, pset, blender, obj_name, obj_type):
pset_name = pset.get_pset_name(obj_name, obj_type)
if obj_type == "Object":
elements = [ifc.get_entity(obj) for obj in blender.get_selected_objects()]
else:
elements = [ifc.get().by_id(blender.get_obj_ifc_definition_id(obj_name, obj_type))]
for element in elements:
if not element:
continue
if not pset.is_pset_applicable(element, pset_name):
continue
ifc_pset = pset.get_element_pset(element, pset_name)
if not ifc_pset:
ifc.run("pset.add_pset", product=element, name=pset_name)
+7 -1
View File
@@ -71,7 +71,11 @@ class Aggregate:
@interface
class Blender: pass
def create_ifc_object(cls, ifc_class, name, data): pass
def get_name(cls, ifc_class, name): pass
def get_obj_ifc_definition_id(cls, obj, obj_type): pass
def get_selected_objects(cls): pass
def set_active_object(cls, obj): pass
@interface
class Boundary: pass
@@ -486,6 +490,8 @@ class Profile:
@interface
class Pset:
def get_element_pset(cls, element, pset_name): pass
def get_pset_name(cls, obj, obj_type): pass
def is_pset_applicable(cls,element, pset_name): pass
@interface
+47 -3
View File
@@ -18,8 +18,7 @@
import bpy
import ifcopenshell.api
import blenderbim.core.tool
from blenderbim.bim.ifc import IfcStore
import blenderbim.tool as tool
class Blender:
@@ -39,7 +38,9 @@ class Blender:
@classmethod
def get_selected_objects(cls):
return set(bpy.context.selected_objects + [bpy.context.active_object])
if bpy.context.selected_objects:
return set(bpy.context.selected_objects + [bpy.context.active_object])
return set([bpy.context.active_object])
@classmethod
def create_ifc_object(cls, ifc_class: str, name: str = None, data=None) -> bpy.types.Object:
@@ -48,3 +49,46 @@ class Blender:
obj = bpy.data.objects.new(name, data)
bpy.ops.bim.assign_class(obj=obj.name, ifc_class=ifc_class)
return obj
@classmethod
def get_obj_ifc_definition_id(cls, obj=None, obj_type=None):
if obj_type == "Object":
return bpy.data.objects.get(obj).BIMObjectProperties.ifc_definition_id
elif obj_type == "Material":
return bpy.data.materials.get(obj).BIMObjectProperties.ifc_definition_id
elif obj_type == "MaterialSet":
return ifcopenshell.util.element.get_material(
tool.Ifc.get_entity(bpy.data.objects.get(obj)), should_skip_usage=True
).id()
elif obj_type == "MaterialSetItem":
return bpy.data.objects.get(obj).BIMObjectMaterialProperties.active_material_set_item_id
elif obj_type == "Task":
return bpy.context.scene.BIMTaskTreeProperties.tasks[
bpy.context.scene.BIMWorkScheduleProperties.active_task_index
].ifc_definition_id
elif obj_type == "Cost":
return bpy.context.scene.BIMCostProperties.cost_items[
bpy.context.scene.BIMCostProperties.active_cost_item_index
].ifc_definition_id
elif obj_type == "Resource":
return bpy.context.scene.BIMResourceTreeProperties.resources[
bpy.context.scene.BIMResourceProperties.active_resource_index
].ifc_definition_id
elif obj_type == "Profile":
return bpy.context.scene.BIMProfileProperties.profiles[
bpy.context.scene.BIMProfileProperties.active_profile_index
].ifc_definition_id
elif obj_type == "WorkSchedule":
return bpy.context.scene.BIMWorkScheduleProperties.active_work_schedule_id
@classmethod
def is_ifc_object(cls, obj):
return bool(obj.BIMObjectProperties.ifc_definition_id)
@classmethod
def is_ifc_class_active(cls, ifc_class):
if bpy.context.active_object:
if cls.is_ifc_object(bpy.context.active_object):
return tool.Ifc.get_entity(bpy.context.active_object).is_a(ifc_class)
return False
return False
+30
View File
@@ -20,6 +20,7 @@ import bpy
import ifcopenshell
import blenderbim.core.tool
import blenderbim.tool as tool
import blenderbim.bim.schema
class Pset(blenderbim.core.tool.Pset):
@@ -28,3 +29,32 @@ class Pset(blenderbim.core.tool.Pset):
pset = ifcopenshell.util.element.get_pset(element, pset_name)
if pset:
return tool.Ifc.get().by_id(pset["id"])
@classmethod
def get_pset_props(cls, obj, obj_type):
if obj_type == "Object":
return bpy.data.objects.get(obj).PsetProperties
elif obj_type == "Material":
return bpy.data.materials.get(obj).PsetProperties
elif obj_type == "MaterialSet":
return bpy.data.objects.get(obj).MaterialSetPsetProperties
elif obj_type == "MaterialSetItem":
return bpy.data.objects.get(obj).MaterialSetItemPsetProperties
elif obj_type == "Task":
return bpy.context.scene.TaskPsetProperties
elif obj_type == "Resource":
return bpy.context.scene.ResourcePsetProperties
elif obj_type == "Profile":
return bpy.context.scene.ProfilePsetProperties
elif obj_type == "WorkSchedule":
return bpy.context.scene.WorkSchedulePsetProperties
@classmethod
def get_pset_name(cls, obj, obj_type):
pset = cls.get_pset_props(obj, obj_type)
print(pset.pset_name)
return pset.pset_name
@classmethod
def is_pset_applicable(cls, element, pset_name):
return bool(pset_name in blenderbim.bim.schema.ifc.psetqto.get_applicable_names(element.is_a(), pset_only=True))