mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-29 16:22:53 +00:00
Fix #7591. Save pset as template now considers all psets in the file, not just the active one.
This commit is contained in:
@@ -569,7 +569,7 @@ class SavePsetAsTemplate(bpy.types.Operator, tool.PsetTemplate.PsetTemplateOpera
|
||||
template_file = IfcStore.pset_template_file
|
||||
assert template_file
|
||||
|
||||
tool.PsetTemplate.add_pset_as_template(pset, template_file)
|
||||
tool.PsetTemplate.add_pset_as_template(pset.Name, template_file)
|
||||
|
||||
template_file.write(IfcStore.pset_template_path)
|
||||
bonsai.bim.handler.refresh_ui_data()
|
||||
|
||||
@@ -61,19 +61,23 @@ class PsetTemplate(bonsai.core.tool.PsetTemplate):
|
||||
tool.Ifc.Operator._execute(self, context)
|
||||
|
||||
@classmethod
|
||||
def add_pset_as_template(
|
||||
cls, pset: ifcopenshell.entity_instance, template_file: ifcopenshell.file
|
||||
) -> ifcopenshell.entity_instance:
|
||||
# TODO: add tests.
|
||||
pset_template = ifcopenshell.api.pset_template.add_pset_template(template_file, pset.Name)
|
||||
for property in pset.HasProperties:
|
||||
ifcopenshell.api.pset_template.add_prop_template(
|
||||
template_file,
|
||||
pset_template,
|
||||
name=property.Name,
|
||||
description=property.Description,
|
||||
primary_measure_type=property.NominalValue.is_a(),
|
||||
)
|
||||
def add_pset_as_template(cls, pset_name: str, template_file: ifcopenshell.file) -> ifcopenshell.entity_instance:
|
||||
added_prop_names = set()
|
||||
pset_template = ifcopenshell.api.pset_template.add_pset_template(template_file, pset_name)
|
||||
for pset in tool.Ifc.get().by_type("IfcPropertySet"):
|
||||
if pset.Name != pset_name:
|
||||
continue
|
||||
for prop in pset.HasProperties:
|
||||
if prop.Name in added_prop_names:
|
||||
continue
|
||||
added_prop_names.add(prop.Name)
|
||||
ifcopenshell.api.pset_template.add_prop_template(
|
||||
template_file,
|
||||
pset_template,
|
||||
name=prop.Name,
|
||||
description=prop.Description,
|
||||
primary_measure_type=prop.NominalValue.is_a(),
|
||||
)
|
||||
return pset_template
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
# Bonsai - OpenBIM Blender Add-on
|
||||
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
||||
#
|
||||
# This file is part of Bonsai.
|
||||
#
|
||||
# Bonsai is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Bonsai is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import bpy
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.pset
|
||||
import bonsai.core.tool
|
||||
import bonsai.tool as tool
|
||||
from bonsai.tool.pset_template import PsetTemplate as subject
|
||||
from test.bim.bootstrap import NewFile
|
||||
|
||||
|
||||
class TestImplementsTool(NewFile):
|
||||
def test_run(self):
|
||||
assert isinstance(subject(), bonsai.core.tool.PsetTemplate)
|
||||
|
||||
|
||||
class TestAddPsetAsTemplate(NewFile):
|
||||
def test_run(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc.set(ifc)
|
||||
element1 = ifc.createIfcWall()
|
||||
element2 = ifc.createIfcWall()
|
||||
pset = ifcopenshell.api.pset.add_pset(ifc, product=element1, name="Foo")
|
||||
prop = ifcopenshell.api.pset.edit_pset(ifc, pset=pset, properties={"Foo": "a"})
|
||||
pset = ifcopenshell.api.pset.add_pset(ifc, product=element2, name="Foo")
|
||||
prop = ifcopenshell.api.pset.edit_pset(ifc, pset=pset, properties={"Bar": "b"})
|
||||
library = ifcopenshell.file()
|
||||
assert (pset_template := subject.add_pset_as_template("Foo", library))
|
||||
assert pset_template.is_a("IfcPropertySetTemplate")
|
||||
assert len(templates := pset_template.HasPropertyTemplates) == 2
|
||||
assert set(t.Name for t in templates) == {"Foo", "Bar"}
|
||||
Reference in New Issue
Block a user