Fixed issues applying arrays

because pset wasn't removed BBIM was recognizing those elements as parts of an array resulting in issues during deletion and duplication. This issue is a regression after ec4f0e5, the root problem was that `keep_objs` wasn't working with `sync_children`.

Since `keep_objs` was used only for applying array layers I've replaced it with `array_layers_to_apply` that works for both `sync_children` = True and False.

https://community.osarch.org/discussion/1831/duplicating-failed-for-array-items-after-apply-array
This commit is contained in:
Andrej730
2023-11-30 16:24:39 +05:00
parent 4fa634cf5c
commit e51d2daf64
3 changed files with 106 additions and 13 deletions
+78
View File
@@ -342,3 +342,81 @@ class TestGenerateStair2DProfile(NewFile):
expected_profile = (verts_data, edges_data, faces_data)
generated_profile = subject.generate_stair_2d_profile(**kwargs)
self.compare_data(generated_profile, expected_profile)
class TestUsingArrays(NewFile):
def setup_array(self, add_second_layer=False, sync_children=False):
bpy.context.scene.BIMProjectProperties.template_file = "0"
bpy.ops.bim.create_project()
bpy.ops.mesh.primitive_cube_add()
obj = bpy.context.active_object
bpy.context.scene.BIMRootProperties.ifc_product = "IfcElement"
bpy.ops.bim.assign_class(ifc_class="IfcActuator", predefined_type="ELECTRICACTUATOR", userdefined_type="")
bpy.ops.bim.add_array()
bpy.ops.bim.enable_editing_array(item=0)
obj.BIMArrayProperties.count = 4
obj.BIMArrayProperties.x = 4
obj.BIMArrayProperties.sync_children = sync_children
bpy.ops.bim.edit_array(item=0)
if add_second_layer:
bpy.ops.bim.add_array()
bpy.ops.bim.enable_editing_array(item=1)
obj.BIMArrayProperties.count = 3
obj.BIMArrayProperties.y = 4
obj.BIMArrayProperties.sync_children = sync_children
bpy.ops.bim.edit_array(item=1)
def test_remove_array_last_to_first(self):
self.setup_array(add_second_layer=True)
bpy.ops.bim.remove_array(item=1)
assert len(bpy.context.selected_objects) == 4
bpy.ops.bim.remove_array(item=0)
assert len(bpy.context.selected_objects) == 1
def test_remove_array_first_to_last(self):
self.setup_array(add_second_layer=True)
bpy.ops.bim.remove_array(item=0)
assert len(bpy.context.selected_objects) == 3
bpy.ops.bim.remove_array(item=0)
assert len(bpy.context.selected_objects) == 1
def test_apply_array_1_layer(self):
self.setup_array()
bpy.ops.bim.apply_array()
objs = bpy.context.selected_objects
assert len(objs) == 4
# check BBIM_Array psets are removed
for obj in objs:
element = tool.Ifc.get_entity(obj)
pset = ifcopenshell.util.element.get_pset(element, "BBIM_Array")
assert pset is None, (obj, pset)
def test_apply_array_multiple_layers(self):
self.setup_array(add_second_layer=True)
bpy.ops.bim.apply_array() # apply second layer
bpy.ops.bim.apply_array() # apply first layer
objs = bpy.context.selected_objects
assert len(objs) == 12
# check BBIM_Array psets are removed
for obj in objs:
element = tool.Ifc.get_entity(obj)
pset = ifcopenshell.util.element.get_pset(element, "BBIM_Array")
assert pset is None, (obj, pset)
def test_apply_array_with_sync_children(self):
self.setup_array(sync_children=True)
bpy.ops.bim.apply_array()
objs = bpy.context.selected_objects
assert len(objs) == 4
# check BBIM_Array psets are removed
for obj in objs:
element = tool.Ifc.get_entity(obj)
pset = ifcopenshell.util.element.get_pset(element, "BBIM_Array")
assert pset is None, (obj, pset)