PDA

View Full Version : Modifying the Default value of an attribute


marcuso
11-02-2010, 08:58 PM
I can specify one, but not seem to modify it in any way. How would you guys do it?

Specifically, I've got a rig that had some attributes changed, like some mouth controls for example. Now I'd like that change to be applied across all scenes using that rig as reference.

marcuso
11-03-2010, 02:05 AM
For example:

import pymel.core as pm

myCube = pm.ls('polyCube1')
pm.attributeQuery(myCube.customAttr, listDefault=True)
>> Return 5.0

pm.setAttr(myCube.customAttr, default=6)
pm.attributeQuery(myCube.customAttr, listDefault=True)
>> Return 6.0

Where is my settAttr with Default flag? :)

NaughtyNathan
11-03-2010, 10:21 AM
don't use setAttr, use addAttr. If you look at the docs for addAttr you can see on the defaultValue flag that it is valid for Creation, Query and Edit. so:

mc.addAttr('myCube.customAttr', e=1, dv=9)However, I fail to see any point to this, the default value is only of any use when you create an attr isn't it? changing the default value is not going to affect any attributes existing values..? I'm confused... :)

:nathaN

marcuso
11-04-2010, 02:00 AM
Oh, hello again :)
I saw that flag in the addAttr, but darnit I never gave it a go! :)

The default value is a neat thing to use in animation since you could have one of your hotkeys setup to reset your selected, or all, values to their default values. Thus, selection all or some of the controls of a rig, and hitting the hotkey, would restore it to its initial state. The same will now be true when I go about changing the defaults in the original rig scene, the face in this case. Hitting the hotkey pops the facial controls to their new defaults. Just a quick thing that makes life prettier.

Like so,

# ================================================================ #
#@setDefaults.py
#
# - Set Default Values -
#
# - Reset channels to default values
# - If nothing is selected, all animatable channels are defaulted.
# - Otherwise, only the selected channels get defaulted.
#
# Written by: Marcus Ottosson
# Updated: Oct 14 2010
# ================================================================ #

import pymel.core as pm

def getSelectedChannels():
# Get the currently selected attributes from the main channelbox.
# From here: http://forums.cgsociety.org/showthread.php?f=89&t=892246&highlight=main+channelbox
channelBox = pm.mel.eval('global string $gChannelBoxName; $temp=$gChannelBoxName;') #fetch maya's main channelbox
attrs = pm.channelBox(channelBox, q=1, sma=1)
if not attrs:
return []
return attrs


def setDefaults():
# Main procedure.
sel = pm.ls(selection=1)
# For every node in selecition #
for node in sel:
# For every animatable attr in the node #
# If no channels are selected:
if getSelectedChannels() == []:
for attr in node.listAnimatable():
# Sort out the actual name of just the attribute.
pAttr = attr.partition('.')[2]
# Figure out the default value for the current attribute.
defaultValue = pm.attributeQuery(pAttr, node=node, ld=1)[0]
# Set the attribute.
attr.set(defaultValue)
else:
for attr in getSelectedChannels():
# Figure out the default value for the current attribute.
defaultValue = pm.attributeQuery(attr, node=node, ld=1)[0]
# Set the attribute.
pm.setAttr(node+"."+attr, defaultValue)

Anyway, thanks. :)

NaughtyNathan
11-04-2010, 10:28 AM
ah! clever idea, and good use for the defaultValue! :)

CGTalk Moderation
11-04-2010, 10:28 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.