Skip to content

Re-implement Nuke imprint#473

Merged
davidlatwe merged 18 commits intogetavalon:masterfrom
davidlatwe:nuke-imprint
Nov 28, 2019
Merged

Re-implement Nuke imprint#473
davidlatwe merged 18 commits intogetavalon:masterfrom
davidlatwe:nuke-imprint

Conversation

@davidlatwe
Copy link
Collaborator

This PR is the first step of refactoring #438, for resolving imprint which functionality was a bit rigid.

What's changed

About lib.imprint

Nuke has three categories of knobs, data-stored knob, layout knob and complex data knob, but let's put complex data knob aside for now.

On data-stored knob, imprint will create knob which fits to regular data types, like bool, int, float, str, list. For dict, it will become a group of knobs, or a group of tabs.

For example:

# Creating two group of knobs
node = nuke.createNode("NoOp")
data = {
    "group1": {
        "group1.var1": 5,
        "group1.var2": "hello",
        "group1.var3": ["a", "b"],
    },
    "group2": {
        "group2.var1": 6,
        "group2.var2": "world",
        "group2.var3": ["o", "p"],
    },
}
lib.imprint(node, data, tab="User")

Which you will get

image

And this:

data = {
    "tabGroup": {
        "tab1": {"count": 5},
        "tab2": {"isGood": True},
        "tab3": {"direction": ["Left", "Right"]},
    },
}
node = nuke.createNode("NoOp")
lib.imprint(node, data, tab="User")

Will looks like this

image

And if you wish to use other kind of knobs which is not mapped in lib.create_knob, you could use lib.Knobby, for example:

data = {
    # Using tuple as key for manual nice naming
    ("my_knob", "Nice Knob"): lib.Knobby("Text_Knob", "Non-editable text"),
    ("divider", ""): lib.Knobby("Text_Knob", ""),
    "MyFilePath": lib.Knobby("File_Knob", "/file/path"),
}
node = nuke.createNode("NoOp")
lib.imprint(node, data, tab="User")

And you have a file path knob

image


Hope this PR make sense to you, please let me know what you think. ☺️

@BigRoy BigRoy requested review from mkolar and tokejepsen November 8, 2019 07:43

instance = [n for n in nodes
if n["name"].value() in self.name] or None
nodes = [n for n in nodes
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be turned into

node = next((n for n in nodes if n["name"].value() in self.name), None)`

Also, the fallback to nuke.allNodes() at the top, would you ever want that to accidentally happen? Seems like that could cause crazy things at some point. You might, I'm just not sure what the intended workflow is.

And, line 161 will cause error on nothing selected None[0]. Maybe better to report a decent error message like "Select X or Y"?

Copy link
Collaborator Author

@davidlatwe davidlatwe Nov 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this has been taken cared by some of the commits in #438 , a bit hard to tell which's which, but from the full changes could see that's been improved.

Should be shipped in next PR :P

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes this has been fixed additionally in #438

Copy link
Collaborator

@tokejepsen tokejepsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice compacting of the knob logic @davidlatwe !

@mkolar
Copy link
Member

mkolar commented Nov 11, 2019

I like it. Certainly cleaner

@davidlatwe
Copy link
Collaborator Author

New minor changes

First two commits (7079c14, 9229fec) were the fixes to complete this PR. The rest were minor improvements.

It's good to be merged now, but I'll be out for travel starting tomorrow till next Thursday so if no other objections, merging this next weekend !

@davidlatwe
Copy link
Collaborator Author

Sorry, just spotted that updating container will create duplicated knobs if existed, commit dc82024 fixed that. And one more change is if given an invalid container node, TypeError will raised. (7715ebd)

That's it !!

return node


def get_avalon_knob_data(node, prefix="avalon:"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to turn this into prefix=["avalon:", "ak:"] for backward compatibility with already running productions? it was previously prefix="ak:"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, okay, but I won't put mutable value as arg's default value, I might hard code it in the for loop below :)

Speaking of which, was there any reason for applying prefix on knobs ?
Would it be okay if we not using prefix in future (with backward compatibility of course) ?

Copy link
Contributor

@jakubjezek001 jakubjezek001 Nov 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be okay if we not using prefix in future (with backward compatibility of course) ?

If you found the efficient way to filter only avalon attributes from all knobs then yes. The reason was to separate only avalon metadata attributes, but didn't see other way to do it ;)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have found a way to list out all user-defined knobs in any given node, just like other host implementations (lib.read). But noted that user-defined layout knobs like tab or group will be listed too.

Here's the gist for trying:
https://gist.github.com/davidlatwe/519528bb01b4ff816389464ec2709e97

Maybe we could work without prefixing knob name if this works ?
Anyway, I'll try resolving this in another PR, this PR will be merged as is for now. ☺️

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting solution!
Listing user defined knobs would definitely be useful.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jezscha I end up implementing the backward compatibility in a new method lib.read, instead of changing lib.get_avalon_knob_data. Please let me know how you think of this, it's in PR #476 😃

@jakubjezek001
Copy link
Contributor

@davidlatwe this PR is awesome! Thanks for help ;)

@davidlatwe davidlatwe merged commit e7eb82f into getavalon:master Nov 28, 2019
@davidlatwe davidlatwe deleted the nuke-imprint branch November 28, 2019 14:12
@davidlatwe davidlatwe mentioned this pull request Dec 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants