Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Completely reset attribute to default state

Completely reset attribute to default state

Anonymous
Not applicable
3,264 Views
1 Reply
Message 1 of 2

Completely reset attribute to default state

Anonymous
Not applicable

Hello,

 

I would like to reset attributes to their default state such as they don't appear in saved file at all.

Thus, for each attribute I would need to get default value, default range, default keyable state, lock state and whatnot.

 

For default value, I tried attributeQuery -listdefaults but some plugins wont return the values.
I had more luck with MfnX_Attribute.default but had to implement it for each different attribute type.

 

Still have no solution for default "keyable" value and such.

 

I wish there was a simple "reset" method but could find one.

Is there any way to do this properly ?

 

Thanks

0 Likes
3,265 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable

I can't think of any single command or API call that will reset an attribute the way that you describe, but here are a few approaches which may work for you, depending upon your needs.

 

If you want to reset all of the target node's attributes, including breaking all of its connections, then delete the node and use the createNode command to create a new one with the same name.

 

If you want to reset all of the target node's attributes, but keep its connections, then rename the node and use the createNode command to create a new one with the same name. Transfer the connections from the from the old node to the new one then delete the old node.

 

If you only want so reset some of the target node's attributes, use the createNode command to create a dummy node of the same type. Use attributeQuery -keyable on the dummy node's attributes to determine their default states and then apply those to the real node. The dummy node's attributes should all be at their default values, so use the copyAttr command to copy those default values to the real node. Unfortunately copyAttr has several restrictions on the types of nodes and attributes it will work with. You may be able to work around those, depending on your situation.

 

In rare circumstances a node might implement a dynamic default for an attribute, so that its default value depends upon the current state of the scene. This is typically done in the node's postConstructor() or getInternalValue() methods. In these cases the value of that attribute in a newly created node will not necessarily match the "real" default value as Maya understands it, so the attribute will still be saved out. You can't really do anything about that. Presumably the attribute has been set to that value for a good reason and attempting to set it to its "real" default could result in the node misbehaving.

0 Likes