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

Maya: Optimize get_related_sets #324

Merged
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 25 additions & 23 deletions client/ayon_core/hosts/maya/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2125,22 +2125,6 @@ def get_related_sets(node):

"""

# Ignore specific suffices
ignore_suffices = ["out_SET", "controls_SET", "_INST", "_CON"]

# Default nodes to ignore
defaults = {"defaultLightSet", "defaultObjectSet"}

# Ids to ignore
ignored = {
AVALON_INSTANCE_ID,
AVALON_CONTAINER_ID,
AYON_INSTANCE_ID,
AYON_CONTAINER_ID,
}

view_sets = get_isolate_view_sets()

sets = cmds.listSets(object=node, extendToShape=False)
if not sets:
return []
Expand All @@ -2151,6 +2135,14 @@ def get_related_sets(node):
# returned by `cmds.listSets(allSets=True)`
sets = cmds.ls(sets)

# Ids to ignore
ignored = {
AVALON_INSTANCE_ID,
AVALON_CONTAINER_ID,
AYON_INSTANCE_ID,
AYON_CONTAINER_ID,
}

# Ignore `avalon.container`
sets = [
s for s in sets
Expand All @@ -2159,21 +2151,31 @@ def get_related_sets(node):
or cmds.getAttr(f"{s}.id") not in ignored
)
]
if not sets:
return sets

# Exclude deformer sets (`type=2` for `maya.cmds.listSets`)
deformer_sets = cmds.listSets(object=node,
extendToShape=False,
type=2) or []
deformer_sets = set(deformer_sets) # optimize lookup
sets = [s for s in sets if s not in deformer_sets]
exclude_sets = cmds.listSets(object=node,
extendToShape=False,
type=2) or []
exclude_sets = set(exclude_sets) # optimize lookup

# Default nodes to ignore
exclude_sets.update({"defaultLightSet", "defaultObjectSet"})

# Filter out the sets to exclude
sets = [s for s in sets if s not in exclude_sets]

# Ignore when the set has a specific suffix
sets = [s for s in sets if not any(s.endswith(x) for x in ignore_suffices)]
ignore_suffices = ("out_SET", "controls_SET", "_INST", "_CON")
iLLiCiTiT marked this conversation as resolved.
Show resolved Hide resolved
sets = [s for s in sets if not s.endswith(ignore_suffices)]
if not sets:
return sets

# Ignore viewport filter view sets (from isolate select and
# viewports)
view_sets = get_isolate_view_sets()
sets = [s for s in sets if s not in view_sets]
sets = [s for s in sets if s not in defaults]
iLLiCiTiT marked this conversation as resolved.
Show resolved Hide resolved

return sets

Expand Down
Loading