Page 1 of 1

Python shading_variables attribute access

Unread postPosted: Tue Aug 07, 2018 9:14 pm
by stheroux
Hello guys,

I'm trying to access shading variables attribute value in python, something like:

python code

my_shading_variables = my_object.get_attribute("shading_variables").get_string()
#or
my_shading_variables = my_object.get_attribute("shading_variables").get_object()

but im not sure what type i'm expecting and none of them seem to work. Passing in a array does not seem to work either.

Thanks
Sylvain

Re: Python shading_variables attribute access

Unread postPosted: Wed Aug 08, 2018 8:51 am
by bvaldes
Hello,

In python you have a wonderful function called dir() this function gives you the method that are accessible from the object given as argument. So if you try to print dir(my_attribute) that will give you all the function that you can use (like get_string(), get_double()...). That will help you in the future to find the right function to do what you want to.

To get the shading variable value of an attr (for example color) do like this:

python code

constant_color = ix.get_item("project://constant_color")
color_attr = constant_color.get_attribute("color")
if color_attr.is_shading_variable_activated(): # Check if the shading variable is activated on this attribute
print color_attr.get_bound_shading_variable() # Get the content of the shading variable


If you need more information, feel free to ask.

Regards

Re: Python shading_variables attribute access

Unread postPosted: Wed Aug 08, 2018 12:57 pm
by stheroux
Hi Benoit,

Sorry might not have been clear, but I'm not looking for a the value of shading variable bounded to an attribute. I'm trying to get the value of attribute named 'shading_variables' (on a GeometryAbMesh in this case).

get_bound_shading_variable() seems to return nothing in this case.

Thanks for the dir() tip, it is very useful.
Sylvain

Re: Python shading_variables attribute access

Unread postPosted: Wed Aug 08, 2018 1:11 pm
by stheroux
So going through all the get() methods, get_raw_string() seems to work.
Il'l go with that.
Thanks
Sylvain

Re: Python shading_variables attribute access

Unread postPosted: Wed Aug 08, 2018 4:44 pm
by bvaldes
Hi,

Sorry for the misunderstanding, happy you found the answer by your own.

Cheers