Hello^^
I want to import certain parameters from a JSON file with python. The loading of the file and parameter import works fine so far, the only thing I'm not sure about is how to correctly convert the color values.
Here is a short script to demonstrate what I'm doing right now.
This will just set a userdata parameter with the name 'Color' on a selected null object to the value [255.0, 94.3499984741211, 76.5]
import c4d
def convert_rgb_to_color(rgb_list):
if len(rgb_list) != 3:
raise ValueError("RGB list must contain exactly 3 values.")
r, g, b = rgb_list
# Normalize 8-bit (0-255) to the range 0.0-1.0
r_normal = r / 255.0
g_normal = g / 255.0
b_normal = b / 255.0
return c4d.Vector(r_normal, g_normal, b_normal)
def main():
# Get the active object
obj = doc.GetActiveObject()
# Check if an object is selected
if obj is None:
print("No object selected.")
return
# Define the color value
color = [255.0, 94.3499984741211, 76.5]
# Convert the color value
color_vector = convert_rgb_to_color(color)
# Check if the object has user data
if not obj.GetUserDataContainer():
print("The selected object has no user data.")
return
# Iterate over the user data on the object
for userdata_id, bc in obj.GetUserDataContainer():
if bc[c4d.DESC_NAME] == "Color":
# Set the user data value to the color vector
obj[userdata_id] = color_vector
c4d.EventAdd()
print("'Color' parameter has been set to:", color_vector)
return
# Execute the script
if __name__ == '__main__':
main()
When the project color management is set to Basic the value gets set to [255,94,77] as expected.
But when the color management is set to OpenColorIO the value gets set to:
sRGB[255,146,143] / RAW[255,94,77].
How could I set the sRGB value to the desired value rather than the RAW value when color Management is OpenColorIO? Like this:
sRGB[255,94,77] / RAW[167,45,25].
I'm Thankfull for any hints on the topic!
Cheers and best regards
Ben