Jamie
1
Hi… I’m after some input about the correct way to do the following…
the code below works as is:
import maya.cmds as cmds
parameters = [
'userAppDir', 'userBitmapsDir', 'userMarkingMenuDir',
'userPrefDir', 'userPresetsDir', 'userScriptDir',
'userShelfDir', 'userTmpDir', 'userWorkspaceDir' ]
userPaths = {}
for parameter in parameters:
## parameter variable won't work as a 'flag' name
# userPaths[parameter] = cmds.internalVar(parameter = True)
# works as a exec
exec "userPaths[\"" + parameter + "\"] = cmds.internalVar(" + parameter + " = True)"
for item in userPaths:
print userPaths[item]
I don’t know the correct way of passing a variable to become a ‘flag’ name as far as syntax goes so I opted to use the exec statement instead…
comments welcome!
Jamie
1 Like
Use ** to pass a dictionary as keyword arguments. (use *, for positional arguments as well)
import maya.cmds as cmds
parameters = [
'userAppDir', 'userBitmapsDir', 'userMarkingMenuDir',
'userPrefDir', 'userPresetsDir', 'userScriptDir',
'userShelfDir', 'userTmpDir', 'userWorkspaceDir' ]
userPaths = {}
for parameter in parameters:
userPaths[paramater] = cmds.internalVar(**{paramater:True})
for item in userPaths:
print userPaths[item]
http://docs.python.org/2/tutorial/controlflow.html#unpacking-argument-lists
Jamie
3
Awesome!
Thanks for the tip bro!
Cheers
J
edit: ended up going with the following for those who are interested…
import maya.cmds as cmds
parameters = [
'userAppDir', 'userBitmapsDir', 'userMarkingMenuDir',
'userPrefDir', 'userPresetsDir', 'userScriptDir',
'userShelfDir', 'userTmpDir', 'userWorkspaceDir' ]
for parameter in parameters:
print ('%-20s %s
' % (parameter, cmds.internalVar(**{parameter:True})))