Need help with scripting to delete all items in a category except 1. I have a script to delete all without any groupings but i can’t find anything that helps with grouped items.
I’ve attached a model that has Matrix1 with groupings and Matrix2 with no groupings. The scripts Action 1 and 2 below the two matrices.
Any help would be greatly appreciated.
One approach is to ungroup the item to be spared, then delete all remaining children in the category (groups or items). I preserved the first item because its index is constant, which simplifies the code. However, you could also adjust to preserve the last item (as your original example did) if desired.
def firstItem = |Matrix1::Cat1|.items
while (firstItem.parent instanceof Group)