Created
January 20, 2016 15:28
-
-
Save BigRoy/3164ece8ec5103639b56 to your computer and use it in GitHub Desktop.
Description of how one could retrieve the "edits" for referenced nodes (draft implementation)
This file contains hidden or 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
"""This is a first draft template that could be used to retrieve the edits on referenced nodes that define a look | |
Next step would be to filter the edits of interest, like shader assignments, sets they are added to, attributes that were added or changed in value. | |
Then we need to store these changes in a format that is artist-friendly and can be re-applied in another scene. | |
""" | |
import maya.cmds as mc | |
from collections import defaultdict | |
def extract_edits(nodes): | |
"""Return a dictionary of data related to the look | |
The given `nodes` must all be referenced nodes. | |
Arguments: | |
nodes (list): The nodes to retrieve the edits for. | |
Returns: | |
dict: Dictionary holding the edits to the nodes | |
that define the look. | |
""" | |
# Only allow referenced nodes | |
assert all(mc.referenceQuery(n, isNodeReferenced=True) for n in nodes) | |
# Store each node per reference node they belong to | |
ref_nodes = defaultdict(list) | |
for node in nodes: | |
ref = mc.referenceQuery(node, referenceNode=True) | |
ref_nodes[ref].append(node) | |
# Get the reference edits for per reference node | |
ref_edits = {} | |
for ref in ref_nodes: | |
# All succesfull edits with their long names | |
edits = mc.referenceQuery(ref, | |
editStrings=True, | |
showNamespace=True, | |
showDagPath=True, | |
failedEdits=False) | |
ref_edits[ref] = edits | |
# Filter edits to those that apply solely to our | |
# subset of nodes instead of all that are in the | |
# referenced scene. | |
for ref, nodes in ref_nodes.iteritems(): | |
edits = ref_edits[ref] | |
for edit in edits: | |
# TODO: Filter to edits that belong to 'nodes' | |
# TODO: Filter the edits we actually want? | |
print edit | |
if __name__ == "__main__": | |
extract_edits(mc.ls(sl=1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment