Delete Multiple Attributes


#1

Hi there. I was wondering if there is a command to delete multiple attribute on ShapeNode and on TransformNode on multiple selected objects. This make me crazy because i’m doing this by hand because on Delete Attribute even with multiple selected Attribute, the delete is step by step, one at time. There are hundreds of Attributes.

Thank you in advance


#2

No there isn’t one but like all life’s other problems it can be solved with python :cool:. I wrote a script once for something similar, here’s a quick and dirty hack of it for your purposes. It does NOT convert transforms to shapes (since you want to process attributes on both). Also, if nothing is selected, it automatically looks at ALL transforms and shapes.

import maya.cmds as cmds
from functools import partial

class MassDeleteAttrWindow(object): 
    def __init__(self):
            self.window = 'massDeleteAttrWin'
            self.title = 'Mass Delete Attributes'
            self.size = (600, 800)
            
    def create(self):
        if cmds.window(self.window, exists=True):
            cmds.deleteUI(self.window, window=True)
        self.window = cmds.window(
            self.window,
            title = self.title,
            widthHeight = self.size
        )
        self.mainForm = cmds.paneLayout(configuration='horizontal3', ps=((1,100,80), (2,100,10)))
        self.uiList = cmds.textScrollList(allowMultiSelection=True)
        self.btnDelete = cmds.button(label='Delete!', command=partial(self.doDelete))
        self.btnRefresh = cmds.button(label='Refresh Selection', command=partial(self.doRefresh))
    
    def getSelection(self):
        self.selection = cmds.ls(selection=True)
        if self.selection == []:
            self.selection = cmds.ls(transforms=True, shapes=True) 
    
    def listCustomAttrs(self):
        attrs = []
        for node in self.selection:
            customAttrs = cmds.listAttr(node, ud=True)
            if customAttrs:
                attrs.extend(customAttrs)
        return sorted(list(set(attrs)))
    
    def doDelete(self, *args):
        attrs = cmds.textScrollList(self.uiList, q=True, selectItem=True)
        for node in self.selection:
            for attr in attrs:
                if cmds.objExists(node) and cmds.attributeQuery(attr, node=node, exists=True):
                    cmds.deleteAttr(node + '.' + attr)
        for attr in attrs:
            cmds.textScrollList(self.uiList, e=True, removeItem=attr)
    
    def doRefresh(self, *args):
        self.getSelection()
        cmds.textScrollList(self.uiList, e=True, removeAll=True)
        cmds.textScrollList(self.uiList, e=True, append=self.listCustomAttrs())
    
    def show(self):
        cmds.showWindow(self.window)
        self.doRefresh()

win = MassDeleteAttrWindow()
win.create()
win.show()



#3

Thank you very much. IS awesome
Cheers.

Dario


#4

Just found this… five years later! Awesome code, really a life saver. Thank you so much!


#5

2023 and Autodesk has 0 plans for anymore functionality to apply commands to all selected objects, than what the Attr Spreadsheet editor was made with, 20yrs ago. Something that other apps have had fully functional, for literally decades. Basic functionality is not something anyone should have to code - that is for special-use stuff.