# Delete subCategories using RiR

**URL:** <https://discourse.mcneel.com/t/delete-subcategories-using-rir/185392>\
**Category:** Revit\
**Tags:** windows\
**Created:** [June 27, 2024, 11:05am UTC](https://discourse.mcneel.com/t/delete-subcategories-using-rir/185392 "2024-06-27T11:05:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![park](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/park/32/771056_2.png) [@park](https://discourse.mcneel.com/u/park)\
**Post date:** [June 27, 2024, 11:05am UTC](https://discourse.mcneel.com/t/delete-subcategories-using-rir/185392/1 "2024-06-27T11:05:58Z")

</div>

Hi @Japhy ,

I was wondering if we can delete every subcategories of the revit template using RiR?

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/1/0/3/10364a02917f9c5d133b78855b0371af1c78a866.png)

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Japhy](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/japhy/32/487647_2.png) [@Japhy](https://discourse.mcneel.com/u/Japhy)\
**Post date:** [June 27, 2024, 1:54pm UTC](https://discourse.mcneel.com/t/delete-subcategories-using-rir/185392/2 "2024-06-27T13:54:06Z")

</div>

PyRevit does this rather well. Note the ‘purgable = True’ property. We have a purge component but it doesn’t appear to be as discriminate.

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/0/a/8/0a81de3d90454d5f3f9af269a6b387510320ca73.png)

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/5/0/0/500ebd1c9d151fec609af7468b42690982367ccc.jpeg)

```auto
"""Reset all model categories and subcategories back to default."""
#pylint: disable=E0401,C0103
from pyrevit import revit
from pyrevit import forms
from pyrevit import script

logger = script.get_logger()

class SubCategoryOption(forms.TemplateListItem):
    def __init__ (self, subcategory):
        super(SubCategoryOption, self). __init__ (subcategory)

    @property
    def name(self):
        return '{} --> {}'.format(self.item.Parent.Name, self.item.Name)

if forms.alert('This tool is very destructive. It resets all '
               'the element subcategories (what is shown in Object Styles '
               'panel) inside this model, effectively resetting all line '
               'styles and all other subcategory of any families imported '
               'in the model. Proceed only if you know what you are doing!\n\n'
               'Are you sure you want to proceed?', yes=True, no=True):
    subcats = revit.query.get_subcategories(doc=revit.doc, purgable=True)
    subcats_to_delete = \
        forms.SelectFromList.show([SubCategoryOption(x) for x in subcats],
                                  title='Select SubCategories to Purge',
                                  button_name='Purge',
                                  multiselect=True,
                                  checked_only=True)
    if subcats_to_delete \
            and forms.alert('Are you sure?', yes=True, no=True):
        with revit.Transaction('Reset SubCategories'):
            revit.delete.delete_elements(subcats_to_delete)
            del subcats_to_delete

```

---

<div class="post-metadata">

**Author:** ![park](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/park/32/771056_2.png) [@park](https://discourse.mcneel.com/u/park)\
**Post date:** [June 28, 2024, 9:52am UTC](https://discourse.mcneel.com/t/delete-subcategories-using-rir/185392/3 "2024-06-28T09:52:40Z")

</div>

Hi @Japhy,

Thanks for the tips. component delete the sub-categories except the sub-categories used in the families of the current document. I found that this is good because we could truly purge the categories…

Thanks heaps again for the tips!

BR,  
Junghwo
