mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 08:24:53 +01:00
removed node argument in on_save, improved function
This commit is contained in:
parent
8b2a129066
commit
52e20f63ff
1 changed files with 24 additions and 19 deletions
|
|
@ -88,7 +88,7 @@ def on_new():
|
||||||
maya.commands.reset_resolution()
|
maya.commands.reset_resolution()
|
||||||
|
|
||||||
|
|
||||||
def on_save(nodes=None):
|
def on_save():
|
||||||
"""Automatically add IDs to new nodes
|
"""Automatically add IDs to new nodes
|
||||||
Any transform of a mesh, without an existing ID,
|
Any transform of a mesh, without an existing ID,
|
||||||
is given one automatically on file save.
|
is given one automatically on file save.
|
||||||
|
|
@ -98,29 +98,33 @@ def on_save(nodes=None):
|
||||||
|
|
||||||
defaults = ["initialShadingGroup", "initialParticleSE"]
|
defaults = ["initialShadingGroup", "initialParticleSE"]
|
||||||
|
|
||||||
# the default items which always want to have an ID
|
ignore = set(cmds.ls(long=True, readOnly=True))
|
||||||
# objectSets include: shading engines, vray object properties
|
locked = set(cmds.ls(long=True, lockedNodes=True))
|
||||||
types = ["mesh", "objectSet", "file", "nurbsCurve"]
|
ignore |= locked
|
||||||
|
|
||||||
|
types = ["shadingEngine", "file"]
|
||||||
|
shape_types = ["mesh", "nurbsCurve"]
|
||||||
|
|
||||||
# the items which need to pass the id to their parent
|
# the items which need to pass the id to their parent
|
||||||
if not nodes:
|
transforms = set()
|
||||||
nodes = (set(cmds.ls(type=types, long=True)) -
|
nodes = set(cmds.ls(type=types, long=True))
|
||||||
set(cmds.ls(long=True, readOnly=True)) -
|
for n in cmds.ls(type=shape_types, long=True):
|
||||||
set(cmds.ls(long=True, lockedNodes=True)))
|
if n in defaults:
|
||||||
|
continue
|
||||||
|
|
||||||
transforms = set()
|
# generate id on parent of shape nodes
|
||||||
for n in cmds.ls(type=types, long=True):
|
parents = cmds.listRelatives(n, parent=True, fullPath=True)
|
||||||
# pass id to parent of node if in subtypes
|
if not parents:
|
||||||
relatives = cmds.listRelatives(n, parent=True, fullPath=True)
|
raise RuntimeError("Bug! Shape has no parent: {0}".format(n))
|
||||||
if not relatives:
|
|
||||||
continue
|
|
||||||
|
|
||||||
for r in cmds.listRelatives(n, parent=True, fullPath=True):
|
for parent in parents:
|
||||||
transforms.add(r)
|
transforms.add(parent)
|
||||||
|
|
||||||
# merge transforms and nodes in one set to make sure every item
|
# Add the collected transform to the nodes
|
||||||
# is unique
|
nodes |= transforms
|
||||||
nodes |= transforms
|
|
||||||
|
# Remove the ignored nodes
|
||||||
|
nodes -= ignore
|
||||||
|
|
||||||
# Lead with asset ID from the database
|
# Lead with asset ID from the database
|
||||||
asset = os.environ["AVALON_ASSET"]
|
asset = os.environ["AVALON_ASSET"]
|
||||||
|
|
@ -129,3 +133,4 @@ def on_save(nodes=None):
|
||||||
if node in defaults:
|
if node in defaults:
|
||||||
continue
|
continue
|
||||||
_set_uuid(str(asset_id["_id"]), node)
|
_set_uuid(str(asset_id["_id"]), node)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue