Python novice here, please excuse me if I'm a bit off on my terminology (and please correct me :) but is it possible to pass flags and values to a 2nd function and for that function in turn to pass them on to a third function?
So something like this:
def changeLayers(var1, var2, layers, flag, value):
# do lots of stuff with var1 and var2...
# finally:
for layer in layers:
changeLayerState(layer, flag = value)
changeLayers('foo', 'bar', someLayers, 'visible', True)
changeLayers('foo', 'bar', otherLayers, 'layerState', 'normal')
So the desired effect is running something like changeLayers('foo', 'bar', someLayers, 'visible', True) and eventually having changeLayerState(layer, visible = True) be evaluated.
If I run something like that I get a Syntax Error, I assume because I'm passing it the string 'visible' as a flag.
This simplifies it a bit but is the essence of what I'm trying to do. Is there a way to do this?
Hope that makes sense..
EDIT: So I was using pseudocode to cast a wide net and not scare anyone off who isn't familiar with Maya Python, but I guess that was more confusing. So here is a snippet that looks at all the display layers in a scene, turns all the ones that end in "Control" to invisible and sets all the ones that end in "Geometry" to a normal layerState (which is to say, not referenced or templated, so that they can be easily selected in the viewport):
import maya.cmds as cmds
layers = cmds.ls(type='displayLayer')
controlLayers = []
geomLayers = []
for layer in layers:
if layer.endswith('Control'):
conLayers.append(layer)
elif layer.endswith('Geometry'):
geomLayers.append(layer)
for layer in controlLayers:
cmds.layerButton(layer, edit = True, layerVisible = False)
cmds.setAttr(layer + '.visiblity' , False)
for layer in geomLayers:
cmds.layerButton(layer, edit = True, layerState = 'normal')
cmds.setAttr(layer + '.displayType', 0)
And that works. But if I try to functionize those lines that change the layer states like this:
import maya.cmds as cmds
layers = cmds.ls(type='displayLayer')
controlLayers = []
geomLayers = []
def changeLayerState(layers, flag, value, attr, attrValue):
for layer in layers:
cmds.layerButton(layer, edit = True, flag = value)
cmds.setAttr(layer + '.' + attr, attrValue)
for layer in layers:
if layer.endswith('Controls'):
controlLayers.append(layer)
elif layer.endswith('Geometry'):
geomLayers.append(layer)
changeLayerState(geomLayers, 'layerState', 'normal', 'displayType', 0)
changeLayerState(controlLayers, 'layerVisible', False, 'visibility', False)
I error out:
// Error: Invalid flag 'flag'
# Traceback (most recent call last):
# File "<maya console>", line 17, in <module>
# File "<maya console>", line 8, in changeLayerState
# TypeError: Invalid flag 'flag' //
Does that make more sense of what I'm trying to do? I'm trying to pass a flag to use on a function from another function.