Skip to content

Commit

Permalink
Merge pull request #324 from BigRoy/enhancement/maya_get_related_sets…
Browse files Browse the repository at this point in the history
…_optimize

Maya: Optimize `get_related_sets`
  • Loading branch information
iLLiCiTiT authored Apr 4, 2024
2 parents fa515ea + aeaf36d commit 9ee2287
Showing 1 changed file with 25 additions and 23 deletions.
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 @@ -2115,22 +2115,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 @@ -2141,6 +2125,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 @@ -2149,21 +2141,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")
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]

return sets

Expand Down

0 comments on commit 9ee2287

Please sign in to comment.