Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attributes' default value not saved in scene #34

Open
benblo opened this issue Oct 27, 2020 · 3 comments
Open

attributes' default value not saved in scene #34

benblo opened this issue Oct 27, 2020 · 3 comments

Comments

@benblo
Copy link

benblo commented Oct 27, 2020

If I create an attribute with a default value, but don't change it, the value is lost after saving & reloading the scene.
I don't know if it's by design or not, but I do see the default value I set appear correctly in the attribute editor, so it's extremely confusing to have the attribute be wiped after reloading the scene.

Here's an all-in-one example:

  • create a new scene, add a sphere
  • add 3 attributes to the sphere, with default values
  • change the value of the first one
  • assign the second one's to the same value
  • don't touch the third one
  • save & reload the scene: you'll see the first attribute's value is "1a", but the second & third are empty!
# create new scene, no prompt
cmds.file(new=True, force=True) # new file, no prompt

sphere = cmdx.encode(cmds.sphere()[0])
sphere.add_attr(cmdx.String("string_1", default="1"))
sphere.add_attr(cmdx.String("string_2", default="2"))
sphere.add_attr(cmdx.String("string_3", default="3"))
sphere["string_1"] = "1a"  # will be saved
sphere["string_2"] = "2"   # will be lost!
                           # string_3 will also be lost!

# save & reload scene, no prompt
scene_path = "test.ma"
cmds.file(rename=scene_path)
cmds.file(save=True, type="mayaAscii")
cmds.file(scene_path, open=True, force=True)
@wougzy
Copy link
Contributor

wougzy commented Oct 31, 2020

That's probably because Maya doesn't support default values for non numeric types. You can't even do that manually.

String.default() should be removed to avoid confusion (or at least removed at addAttr)

@mottosso
Copy link
Owner

mottosso commented Nov 1, 2020

Strange that it assigns the value at all. :/

We could remove it, but I think we should handle it instead. No reason this shouldn't work other than a Maya API limitation, and we can just regularly assign it post-creation to keep all attributes uniform and working as expected.

Anyone interested in tackling this?

@benblo
Copy link
Author

benblo commented Nov 1, 2020

I have a workaround already, it’s ugly but I can kick a PR tomorrow-ish.
What’s weird is the OM API accepts the default for TypedAttr, it’s even custom handled by cmdx to convert the python str to MObj (plus reassigning the same value doesn’t trigger a dirty so the default is tracked)... so it really looks like it should work, it’s just not saved in scene.

benblo pushed a commit to benblo/cmdx that referenced this issue Nov 4, 2020
- see mottosso#34
- handles Compounds recursively
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants