diff --git a/src/blenderbim/blenderbim/bim/module/pset/operator.py b/src/blenderbim/blenderbim/bim/module/pset/operator.py index 9347d9f8f7..b306ebba76 100644 --- a/src/blenderbim/blenderbim/bim/module/pset/operator.py +++ b/src/blenderbim/blenderbim/bim/module/pset/operator.py @@ -361,9 +361,16 @@ class CopyPropertyToSelection(bpy.types.Operator, Operator): name: bpy.props.StringProperty() def _execute(self, context): + is_pset = tool.Ifc.get().by_id(context.active_object.PsetProperties.active_pset_id).is_a("IfcPropertySet") pset_name = context.active_object.PsetProperties.active_pset_name prop_value = context.active_object.PsetProperties.properties.get(self.name).get_value() for obj in context.selected_objects: core.copy_property_to_selection( - tool.Ifc, tool.Pset, obj=obj, pset_name=pset_name, prop_name=self.name, prop_value=prop_value + tool.Ifc, + tool.Pset, + obj=obj, + is_pset=is_pset, + pset_name=pset_name, + prop_name=self.name, + prop_value=prop_value, ) diff --git a/src/blenderbim/blenderbim/core/pset.py b/src/blenderbim/blenderbim/core/pset.py index b568e05d29..403955ba7c 100644 --- a/src/blenderbim/blenderbim/core/pset.py +++ b/src/blenderbim/blenderbim/core/pset.py @@ -17,11 +17,14 @@ # along with BlenderBIM Add-on. If not, see . -def copy_property_to_selection(ifc, pset, obj=None, pset_name=None, prop_name=None, prop_value=None): +def copy_property_to_selection(ifc, pset, is_pset=True, obj=None, pset_name=None, prop_name=None, prop_value=None): element = ifc.get_entity(obj) if not element: return ifc_pset = pset.get_element_pset(element, pset_name) if not ifc_pset: - ifc_pset = ifc.run("pset.add_pset", product=element, name=pset_name) - ifc.run("pset.edit_pset", pset=ifc_pset, properties={prop_name: prop_value}) + ifc_pset = ifc.run("pset.add_pset" if is_pset else "pset.add_qto", product=element, name=pset_name) + if is_pset: + 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}) diff --git a/src/blenderbim/test/bim/feature/pset.feature b/src/blenderbim/test/bim/feature/pset.feature index e5f624ceb0..7a14662c2e 100644 --- a/src/blenderbim/test/bim/feature/pset.feature +++ b/src/blenderbim/test/bim/feature/pset.feature @@ -1,7 +1,7 @@ @pset Feature: Pset -Scenario: Copy property to selected +Scenario: Copy property to selected - copy property Given an empty IFC project And I add a cube And the object "Cube" is selected @@ -20,3 +20,23 @@ Scenario: Copy property to selected And I set "active_object.PsetProperties.properties[2].string_value" to "Foo" When I press "bim.copy_property_to_selection(name='FireRating')" Then nothing happens + +Scenario: Copy property to selected - copy quantity + Given an empty IFC project + And I add a cube + And the object "Cube" is selected + And I set "scene.BIMRootProperties.ifc_class" to "IfcWall" + And I press "bim.assign_class" + And I add a cube + And the object "Cube" is selected + And I set "scene.BIMRootProperties.ifc_class" to "IfcWall" + And I press "bim.assign_class" + And the object "IfcWall/Cube" is selected + And additionally the object "IfcWall/Cube.001" is selected + And I set "active_object.PsetProperties.pset_name" to "Pset_BuildingElementCommon" + And I press "bim.add_qto(obj='IfcWall/Cube.001', obj_type='Object')" + And the variable "qto" is "{ifc}.by_type('IfcQuantitySet')[-1].id()" + And I press "bim.enable_pset_editing(obj='IfcWall/Cube.001', obj_type='Object', pset_id={qto})" + And I set "active_object.PsetProperties.properties[0].float_value" to "1" + When I press "bim.copy_property_to_selection(name='Length')" + Then nothing happens diff --git a/src/blenderbim/test/core/test_pset.py b/src/blenderbim/test/core/test_pset.py index f12dc96858..7ef8cff0c4 100644 --- a/src/blenderbim/test/core/test_pset.py +++ b/src/blenderbim/test/core/test_pset.py @@ -24,7 +24,7 @@ class TestCopyPropertyToSelection: def test_doing_nothing_if_object_is_not_an_element(self, ifc, pset): ifc.get_entity("obj").should_be_called().will_return(None) subject.copy_property_to_selection( - ifc, pset, obj="obj", pset_name="pset_name", prop_name="prop_name", prop_value="prop_value" + ifc, pset, is_pset=True, obj="obj", pset_name="pset_name", prop_name="prop_name", prop_value="prop_value" ) def test_copying_the_property_to_an_existing_pset(self, ifc, pset): @@ -32,7 +32,7 @@ class TestCopyPropertyToSelection: pset.get_element_pset("element", "pset_name").should_be_called().will_return("pset") ifc.run("pset.edit_pset", pset="pset", properties={"prop_name": "prop_value"}).should_be_called() subject.copy_property_to_selection( - ifc, pset, obj="obj", pset_name="pset_name", prop_name="prop_name", prop_value="prop_value" + ifc, pset, is_pset=True, obj="obj", pset_name="pset_name", prop_name="prop_name", prop_value="prop_value" ) def test_creating_a_new_pset_if_it_doesnt_exist(self, ifc, pset): @@ -41,5 +41,22 @@ class TestCopyPropertyToSelection: ifc.run("pset.add_pset", product="element", name="pset_name").should_be_called().will_return("pset") ifc.run("pset.edit_pset", pset="pset", properties={"prop_name": "prop_value"}).should_be_called() subject.copy_property_to_selection( - ifc, pset, obj="obj", pset_name="pset_name", prop_name="prop_name", prop_value="prop_value" + ifc, pset, is_pset=True, obj="obj", pset_name="pset_name", prop_name="prop_name", prop_value="prop_value" + ) + + def test_copying_the_quantity_to_an_existing_qto(self, ifc, pset): + ifc.get_entity("obj").should_be_called().will_return("element") + pset.get_element_pset("element", "qto_name").should_be_called().will_return("qto") + ifc.run("pset.edit_qto", qto="qto", properties={"prop_name": "prop_value"}).should_be_called() + subject.copy_property_to_selection( + ifc, pset, is_pset=False, obj="obj", pset_name="qto_name", prop_name="prop_name", prop_value="prop_value" + ) + + def test_creating_a_new_qto_if_it_doesnt_exist(self, ifc, pset): + ifc.get_entity("obj").should_be_called().will_return("element") + pset.get_element_pset("element", "qto_name").should_be_called().will_return(None) + ifc.run("pset.add_qto", product="element", name="qto_name").should_be_called().will_return("qto") + ifc.run("pset.edit_qto", qto="qto", properties={"prop_name": "prop_value"}).should_be_called() + subject.copy_property_to_selection( + ifc, pset, is_pset=False, obj="obj", pset_name="qto_name", prop_name="prop_name", prop_value="prop_value" )