mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
Bonsai - set active bsdd when loading project
When loading an ifc project it will search it for bsdd ifcclassifications and will set one as active if finds it, so now it will be a bit more convenient working with bsdd classification assignment as it active bsdd previously was always getting reset when you reload ifc file. Example - https://imgur.com/a/stlJqwm
This commit is contained in:
@@ -282,6 +282,7 @@ class IfcImporter:
|
||||
tool.Spatial.run_spatial_import_spatial_decomposition()
|
||||
if default_container := tool.Spatial.guess_default_container():
|
||||
tool.Spatial.set_default_container(default_container)
|
||||
tool.Loader.setup_active_bsdd_classification()
|
||||
self.update_progress(100)
|
||||
bpy.context.window_manager.progress_end()
|
||||
|
||||
|
||||
@@ -924,3 +924,21 @@ class Loader(bonsai.core.tool.Loader):
|
||||
mesh["ios_materials"] = [m.instance_id() for m in geometry.materials]
|
||||
mesh["ios_material_ids"] = geometry.material_ids
|
||||
return mesh
|
||||
|
||||
@classmethod
|
||||
def setup_active_bsdd_classification(cls):
|
||||
ifc_file = tool.Ifc.get()
|
||||
attr_name = "Specification" if ifc_file.schema == "IFC4X3" else "Location"
|
||||
bsdd_classification, uri, name = None, None, None
|
||||
for c in ifc_file.by_type("IfcClassification"):
|
||||
if (
|
||||
(uri := getattr(c, attr_name))
|
||||
and uri.startswith("https://identifier.buildingsmart.org/uri/")
|
||||
and (name := c.Name)
|
||||
):
|
||||
bsdd_classification = c
|
||||
break
|
||||
if not bsdd_classification:
|
||||
return
|
||||
assert name and uri
|
||||
tool.Bsdd.set_active_bsdd(name, uri)
|
||||
|
||||
@@ -510,3 +510,18 @@ class TestLoadingIndexedMap(NewFile):
|
||||
blender_color = Vector(layer.data[loop_i].color)
|
||||
ifc_color = Vector(colors[color_index[face_i]] + (1.0,))
|
||||
assert tool.Cad.are_vectors_equal(blender_color, ifc_color)
|
||||
|
||||
|
||||
class TestSetupActiveBsddClassification(NewFile):
|
||||
def test_run(self):
|
||||
bpy.ops.bim.create_project()
|
||||
ifc_file = tool.Ifc.get()
|
||||
name = "CCI Construction"
|
||||
uri = "https://identifier.buildingsmart.org/uri/molio/cciconstruction/1.0"
|
||||
ifc_file.create_entity("IfcClassification", Name=name, Location=uri)
|
||||
filepath = "test/files/temp/test.ifc"
|
||||
ifc_file.write(filepath)
|
||||
bpy.ops.bim.load_project(filepath=filepath)
|
||||
props = bpy.context.scene.BIMBSDDProperties
|
||||
assert props.active_domain == name
|
||||
assert props.active_uri == uri
|
||||
|
||||
Reference in New Issue
Block a user