Hey there! I am back. First of all. Happy New Year! I hope to keep posting things.
This post will be brief. Some times we need to set a default values for float or integer attributes on the channel box. Maya doesn't have a tool to do that, you need to do it by cmds. This is particularly useful when the default value is not 0. We can use the next command to query the default value, to reset the attribute.
dValue = mc.addAttr(source + '.' + attr, q=1,dv=1) mc.setAttr(source + '.' +attr, dValue)
So, I built a simple tool for that. You just need to select a custom attribute float or integer and press the button. The value won't change, but internally the default value will.
The code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
######################################################################################################################## | |
AUTHOR: | |
Steffano Richi (steffano.richi@gmail.com) | |
https://encci20.blogspot.pe/ | |
16.04.2023 | |
DESCRIPTION: | |
Set Default Attr for float and integers | |
USAGE: | |
*Put in maya/scripts | |
*Run the next code in scriptEditor in Python | |
import wrSetDefault as wrSetDefault | |
wrSetDefault.ui() | |
######################################################################################################################## | |
""" | |
import maya.cmds as mc | |
def setDefault(self): | |
nodes = mc.channelBox('mainChannelBox',q=True,mol=True) | |
attrs = mc.channelBox('mainChannelBox',q=True,sma=True) | |
defV = mc.floatField('floatSetDefault',q=True,v=1) | |
for node in nodes: | |
for attr in attrs: | |
try: | |
mc.addAttr(node + '.' + attr,e=1,dv=defV) | |
except: | |
mc.warning('The ' + node + '.' + attr + ' can not set a default value') | |
def ui(): | |
w = 160 | |
h = 60 | |
if mc.window('wrSetDefaultValue',ex=True): | |
mc.deleteUI('wrSetDefaultValue') | |
mc.window('wrSetDefaultValue',t='Set Default',s=False,mxb=False,mnb=False) | |
mc.window('wrSetDefaultValue',e=1,w=w,h=h) | |
mc.columnLayout(adj=1,rs=8,cat=['both',20]) | |
mc.rowLayout(nc=2,adj=2) | |
mc.columnLayout(adj=1,rs=5) | |
mc.text(align='right',l='Value:',h=20) | |
mc.setParent('..') | |
mc.columnLayout(adj=1,rs=5) | |
mc.floatField('floatSetDefault',h=20,v=0) | |
mc.setParent('..') | |
mc.setParent('..') | |
mc.button(l='Set Default',bgc=[1, 0.5, 0],c=setDefault) | |
mc.showWindow('wrSetDefaultValue') |
I hope you find this helpful. Thanks
No comments:
Post a Comment