Isotropix Forums

Initialising all attribute defaults for OfClass

Clarisse Scripting related topics

Initialising all attribute defaults for OfClass

Unread postby briansilva » Tue May 26, 2020 10:39 pm

Hello!

I'm generating some description files based on the defaults for Clarisse nodes. The best place to get this info seems to be from the OfClass objects, which is working for almost everything. There do seem to be a few attributes, though, that require some sort of initialisation, and I haven't been able to figure out the proper way to do this.

For example, the file_color_space attribute on TextureStreamedMapFile:

python code

clrs_attr = ix.application.get_factory().get_classes().get("TextureStreamedMapFile").get_proto().get_attribute("file_color_space")
print clrs_attr

values = ix.api.CoreStringArray(clrs_attr.get_value_count())
clrs_attr.get_values(values)
print values[0]

when run from a newly opened scene produces:
Code: Select all
protos://TextureStreamedMapFile_Proto.file_color_space
__invalid_enum_label__


but, if I create an instance of a TextureStreamedMapFile through the UI, then run the same code, it outputs this:
Code: Select all
protos://TextureStreamedMapFile_Proto.file_color_space
Clarisse|linear


Creating an instance through code is always an option, but is there another way to do this cleanly without creating objects?

Any insight into what this initialisation step is doing in general would be a bonus and appreciated, too. :D

Thank you!
briansilva
 
Posts: 64
Joined: Mon Mar 25, 2019 12:43 pm

Re: Initialising all attribute defaults for OfClass

Unread postby dcourtois » Tue Jun 23, 2020 9:09 am

Hi,

Sorry for the late reply. Some attributes are initialized on the first creation of an object of that type because their value can depend on the stuff that are loaded after the OfClass is actually created.

In your cases, the color space is an enum, and this enum is initialized based on the color spaces loaded from some other part of the code (I'm not really familiar with these parts, but I thinks it has to do with OpenColorIO and configuration files)

Anyway in your case, here is how you can get the value:

python code

clrs_attr = ix.application.get_factory().get_classes().get("TextureStreamedMapFile").get_proto().get_attribute("file_color_space")
print clrs_attr

color_space = clrs_attr.get_string()
if color_space == ix.api.OfEnum.get_invalid_label():
color_space_enum = ix.application.get_factory().get_enum("color_space")
color_space = color_space_enum.get_label(0)

print color_space


Basically you check the invalid enum value, and in this case return the first available color space from the enum (which is initialized when the script is executed) This is how it works internally.
User avatar
dcourtois
 
Posts: 94
Joined: Tue Jul 25, 2017 3:15 pm


Return to Scripting