Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Dont brute force the colorspace list
Browse files Browse the repository at this point in the history
  • Loading branch information
tokejepsen committed Mar 7, 2024
1 parent 1d16f25 commit b976a5d
Showing 1 changed file with 18 additions and 23 deletions.
41 changes: 18 additions & 23 deletions openpype/hosts/nuke/api/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
import re

import nuke

from openpype import resources
Expand Down Expand Up @@ -110,35 +112,28 @@ def colorspace_exists_on_node(node, colorspace_name):
def get_colorspace_list(colorspace_knob):
"""Get available colorspace profile names
Because the values returned from colorspace_knob.values() do not correspond
to the value returned from colorspace_knob.value(), and the extracted
colorspace comes from using colorspace_knob.value(), we need to iterate
through all values to get the correct value.
A code example of the above would be:
for count, value in enumerate(colorspace_knob.values()):
colorspace_knob.setValue(count)
print(colorspace_knob.value() in colorspace_knob.values())
Args:
colorspace_knob (nuke.Knob): nuke knob object
Returns:
list: list of strings names of profiles
"""
original_value = colorspace_knob.value()

colorspaces = []

try:
for count, _ in enumerate(colorspace_knob.values()):
colorspace_knob.setValue(count)
colorspaces.append(colorspace_knob.value())
finally:
colorspace_knob.setValue(original_value)

return colorspaces
results = []

# This pattern is to match with roles which uses an indentation and
# parentheses with original colorspace. The value returned from the
# colorspace is the string before the indentation, so we'll need to
# convert the values to match with value returned from the knob,
# ei. knob.value().
pattern = r".*\t.* \(.*\)"
for colorspace in nuke.getColorspaceList(colorspace_knob):
match = re.search(pattern, colorspace)
if match:
results.append(colorspace.split("\t")[0])
else:
results.append(colorspace)

return results


def is_headless():
Expand Down

0 comments on commit b976a5d

Please sign in to comment.