BIM tool can now add parametric profiles for beams, not just columns.

This commit is contained in:
Dion Moult
2021-07-18 14:48:30 +10:00
parent 32062e4085
commit 9a14406f92
3 changed files with 30 additions and 23 deletions
@@ -1,7 +1,7 @@
import bpy import bpy
import ifcopenshell import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
from blenderbim.bim.module.model import product, wall, slab, column from blenderbim.bim.module.model import product, wall, slab, profile
from blenderbim.bim.ifc import IfcStore from blenderbim.bim.ifc import IfcStore
from bpy.app.handlers import persistent from bpy.app.handlers import persistent
@@ -51,17 +51,17 @@ def load_post(*args):
"type.assign_type", "BlenderBIM.DumbSlab.RegenerateFromType", slab.DumbSlabPlaner().regenerate_from_type "type.assign_type", "BlenderBIM.DumbSlab.RegenerateFromType", slab.DumbSlabPlaner().regenerate_from_type
) )
IfcStore.add_element_listener(column.element_listener) IfcStore.add_element_listener(profile.element_listener)
ifcopenshell.api.add_pre_listener( ifcopenshell.api.add_pre_listener(
"geometry.add_representation", "BlenderBIM.DumbColumn.EnsureSolid", column.ensure_solid "geometry.add_representation", "BlenderBIM.DumbProfile.EnsureSolid", profile.ensure_solid
) )
ifcopenshell.api.add_post_listener( ifcopenshell.api.add_post_listener(
"material.edit_profile", "material.edit_profile",
"BlenderBIM.DumbColumn.RegenerateFromProfile", "BlenderBIM.DumbProfile.RegenerateFromProfile",
column.DumbColumnRegenerator().regenerate_from_profile, profile.DumbProfileRegenerator().regenerate_from_profile,
) )
ifcopenshell.api.add_post_listener( ifcopenshell.api.add_post_listener(
"type.assign_type", "type.assign_type",
"BlenderBIM.DumbColumn.RegenerateFromType", "BlenderBIM.DumbProfile.RegenerateFromType",
column.DumbColumnRegenerator().regenerate_from_type, profile.DumbProfileRegenerator().regenerate_from_type,
) )
@@ -4,7 +4,7 @@ import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.element import ifcopenshell.util.element
import ifcopenshell.util.representation import ifcopenshell.util.representation
from . import wall, slab, column from . import wall, slab, profile
from blenderbim.bim.ifc import IfcStore from blenderbim.bim.ifc import IfcStore
from ifcopenshell.api.pset.data import Data as PsetData from ifcopenshell.api.pset.data import Data as PsetData
from mathutils import Vector, Matrix from mathutils import Vector, Matrix
@@ -36,8 +36,9 @@ class AddTypeInstance(bpy.types.Operator):
obj = slab.DumbSlabGenerator(self.file.by_id(int(relating_type))).generate() obj = slab.DumbSlabGenerator(self.file.by_id(int(relating_type))).generate()
if obj: if obj:
return {"FINISHED"} return {"FINISHED"}
elif ifc_class == "IfcColumnType": elif ifc_class in ["IfcColumnType", "IfcBeamType"]:
obj = column.DumbColumnGenerator(self.file.by_id(int(relating_type))).generate() obj = profile.DumbProfileGenerator(self.file.by_id(int(relating_type))).generate()
return {"FINISHED"}
if obj: if obj:
return {"FINISHED"} return {"FINISHED"}
# A cube # A cube
@@ -31,7 +31,7 @@ def mode_callback(obj, data):
return return
product = IfcStore.get_file().by_id(obj.BIMObjectProperties.ifc_definition_id) product = IfcStore.get_file().by_id(obj.BIMObjectProperties.ifc_definition_id)
parametric = ifcopenshell.util.element.get_psets(product).get("EPset_Parametric") parametric = ifcopenshell.util.element.get_psets(product).get("EPset_Parametric")
if not parametric or parametric["Engine"] != "BlenderBIM.DumbColumn": if not parametric or parametric["Engine"] != "BlenderBIM.DumbProfile":
return return
IfcStore.edited_objs.add(obj) IfcStore.edited_objs.add(obj)
bm = bmesh.from_edit_mesh(obj.data) bm = bmesh.from_edit_mesh(obj.data)
@@ -43,7 +43,7 @@ def mode_callback(obj, data):
def ensure_solid(usecase_path, ifc_file, settings): def ensure_solid(usecase_path, ifc_file, settings):
product = ifc_file.by_id(settings["blender_object"].BIMObjectProperties.ifc_definition_id) product = ifc_file.by_id(settings["blender_object"].BIMObjectProperties.ifc_definition_id)
parametric = ifcopenshell.util.element.get_psets(product).get("EPset_Parametric") parametric = ifcopenshell.util.element.get_psets(product).get("EPset_Parametric")
if not parametric or parametric["Engine"] != "BlenderBIM.DumbColumn": if not parametric or parametric["Engine"] != "BlenderBIM.DumbProfile":
return return
material = ifcopenshell.util.element.get_material(product) material = ifcopenshell.util.element.get_material(product)
if material and material.is_a("IfcMaterialProfileSetUsage"): if material and material.is_a("IfcMaterialProfileSetUsage"):
@@ -53,7 +53,7 @@ def ensure_solid(usecase_path, ifc_file, settings):
settings["ifc_representation_class"] = "IfcExtrudedAreaSolid/IfcMaterialProfileSetUsage" settings["ifc_representation_class"] = "IfcExtrudedAreaSolid/IfcMaterialProfileSetUsage"
class DumbColumnGenerator: class DumbProfileGenerator:
def __init__(self, relating_type): def __init__(self, relating_type):
self.relating_type = relating_type self.relating_type = relating_type
@@ -75,9 +75,9 @@ class DumbColumnGenerator:
def derive_from_cursor(self): def derive_from_cursor(self):
self.location = bpy.context.scene.cursor.location self.location = bpy.context.scene.cursor.location
return self.create_column() return self.create_profile()
def create_column(self): def create_profile(self):
# A cube # A cube
verts = [ verts = [
Vector((-1, -1, -1)), Vector((-1, -1, -1)),
@@ -99,17 +99,23 @@ class DumbColumnGenerator:
[0, 2, 6, 4], [0, 2, 6, 4],
] ]
mesh = bpy.data.meshes.new(name="Dumb Column") mesh = bpy.data.meshes.new(name="Dumb Profile")
mesh.from_pydata(verts, edges, faces) mesh.from_pydata(verts, edges, faces)
obj = bpy.data.objects.new("Column", mesh) obj = bpy.data.objects.new("Profile", mesh)
obj.name = "Column"
obj.location = self.location obj.location = self.location
if self.collection_obj and self.collection_obj.BIMObjectProperties.ifc_definition_id: if self.collection_obj and self.collection_obj.BIMObjectProperties.ifc_definition_id:
obj.location[2] = self.collection_obj.location[2] obj.location[2] = self.collection_obj.location[2]
self.collection.objects.link(obj) self.collection.objects.link(obj)
bpy.ops.bim.assign_class( if self.relating_type.is_a("IfcColumnType"):
obj=obj.name, ifc_class="IfcColumn", predefined_type="COLUMN", should_add_representation=False obj.name = "Column"
) bpy.ops.bim.assign_class(
obj=obj.name, ifc_class="IfcColumn", predefined_type="COLUMN", should_add_representation=False
)
elif self.relating_type.is_a("IfcBeamType"):
obj.name = "Beam"
bpy.ops.bim.assign_class(
obj=obj.name, ifc_class="IfcBeam", predefined_type="BEAM", should_add_representation=False
)
element = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id) element = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
bpy.ops.bim.assign_type(relating_type=self.relating_type.id(), related_object=obj.name) bpy.ops.bim.assign_type(relating_type=self.relating_type.id(), related_object=obj.name)
profile_set_usage = ifcopenshell.util.element.get_material(element) profile_set_usage = ifcopenshell.util.element.get_material(element)
@@ -124,13 +130,13 @@ class DumbColumnGenerator:
obj=obj.name, ifc_definition_id=representation.id(), should_reload=True, should_switch_all_meshes=True obj=obj.name, ifc_definition_id=representation.id(), should_reload=True, should_switch_all_meshes=True
) )
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="EPset_Parametric") pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="EPset_Parametric")
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Engine": "BlenderBIM.DumbColumn"}) ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Engine": "BlenderBIM.DumbProfile"})
MaterialData.load(self.file) MaterialData.load(self.file)
obj.select_set(True) obj.select_set(True)
return obj return obj
class DumbColumnRegenerator: class DumbProfileRegenerator:
def regenerate_from_profile(self, usecase_path, ifc_file, settings): def regenerate_from_profile(self, usecase_path, ifc_file, settings):
self.file = IfcStore.get_file() self.file = IfcStore.get_file()
self.unit_scale = ifcopenshell.util.unit.calculate_unit_scale(ifc_file) self.unit_scale = ifcopenshell.util.unit.calculate_unit_scale(ifc_file)