Selecting multiple objects and applying attribute using python in maya


#1

Hello,
I’m a new·bie in programming and always get stuck at functions, for loops, pretty much everything… @_@ …
I was hoping that somebody can help me to create a script that can "select multiple objects and apply “HoldOut” attribute to all of them at one click.

This is what I came up with so far…
Mainly… just creating a window with the option buttons…
@_@

import maya.cmds as cmds


def selAll(*args):
    list = cmds.select(cmds.listRelatives(cmds.ls(geometry=True),p=True, path=True), r=True)

def hold(*args):
    checkList = cmds.ls(sl=1)
    cmds.setAttr('checkList.holdOut',1)

def holdoutWindow():
    if cmds.window('HoldOutWindow', exists=True):
        cmds.deleteUI('HoldOutWindow')
       
    bigMainWindow = cmds.window('HoldOutWindow', t= 'Hold Out Geos', sizeable=True, mnb=False, mxb=False)
    cmds.columnLayout(adj=True, rowSpacing =5)
   
    cmds.button( label="Select All Geometry", command=selAll)
    cmds.button( label="Hold Out ON/OFF", command=hold)
   
   
    cmds.separator(h=10, style='none')    
    cmds.button(label = 'CLOSE', command = closingWindow)
   
    cmds.showWindow( bigMainWindow )
   
def closingWindow(arg=None):
    cmds.deleteUI('HoldOutWindow', window =True)

Thanks !