Access and Modify Subcategories in Family Document

I am looking to write a script (or scripts) that can automates the cleanup of about 170 casework families for me. These families have too many sub-categories (example: “Cabinet - Base”, “Cabinet - Door”, “Cabinet - Back”, etc). I want to simplify the subcategories by assigning all elements with a subcategory name that contains “Cabinet” to a “Cabinet” subcategory, and assign all elements with a subcategory name that contains “Glass” to a “Glass” subcategory.

The process below is what I’m trying to execute:

1. Create 'Cabinet' and 'Glass' subcategories in a family
2. Select elements by a specified keyword in their assigned subcategory. For example, select elements with subcategory name that contains 'Cabinet' and does not contain 'Glass'
3. Assign those elements to the new subcategory
4. Assign material parameter based on subcategory. For example, the material parameter of all elements with the subcategory 'Cabinet' should be associated to the material parameter, 'Cabinet Material', and all elements with the 'Glass' subcategory should be associated to the material parameter, 'Glass Material'.
5. Delete all unused subcategories.

I figured out step 1, but am having trouble finding nodes that allow me to perform the other functionality using sub-categories in the family editor. Orchid has some useful nodes for working with subcategories in the project environment, and Clockwork has a node that works to create subcategories in the family editor, but the main functions I’m searching for and having trouble finding are:

• Selecting elements by subcategory in family editor (or selecting all elements and filtering selection by subcategory)
• Changing the subcategory of those selected elements
• Associating material to a family parameter based on subcategory name
• Deleting unused subcategories

Is someone able to point me in the right direction to where I might find this functionality, or suggest an alternative approach? It would be greatly appreciated.

Without seeing how you’re accessing these elements (ie: are you in the active family document or are you open ting many family documents) it’s tough to help.

That said I would look to select all form elements and assign the subcategory for each rather than try to select by sub category.

Best to post what you have tried so far so that the community can provide some guidance.