Isotropix Forums

Getting OfObject attributes by name

Clarisse Scripting related topics

Getting OfObject attributes by name

Unread postby briansilva » Tue Feb 04, 2020 4:34 pm

I know this is a little obscure, but I need to access attributes on an OfObject by name. I was hoping to use the simplified method provided, like:

Code: Select all
obj.attrs["filename"]


so that I could still avoid the need to test for data type, but this doesn't work. It seems the magic behind this doesn't respond to getattr either.

Is there any way to do this?

Thank you!
Last edited by briansilva on Tue Feb 04, 2020 5:21 pm, edited 1 time in total.
briansilva
 
Posts: 51
Joined: Mon Mar 25, 2019 12:43 pm

Re: Using

Unread postby dcourtois » Tue Feb 04, 2020 5:07 pm

I don't understand what you mean by "the simplified method provided". We don't provide such method... And what do you mean by "so that I could still avoid the need to test for data type" ??

Anyway the way to get an attribute is

python code

obj.get_attribute("filename")
if that is what you wanted to know.
User avatar
dcourtois
 
Posts: 73
Joined: Tue Jul 25, 2017 3:15 pm

Re: Getting OfObject attributes by name

Unread postby briansilva » Tue Feb 04, 2020 5:28 pm

Sorry I was vague!

What I meant by the "simplified method" is this:
https://clarissewiki.com/4.0/sdk/simpli ... ython_attr

So instead of this:
Code: Select all
obj.get_attribute('unseen_by_camera').set_bool(False)


where you have to know the data type of the attribute (to choose whether you need set_bool, set_string, set_vec3d, etc.), you can do this:
Code: Select all
obj.attrs.unseen_by_camera = False


I'd like to access the attribute with a name string ('unseen_by_camera') but not have to know the data type function required to set it.
briansilva
 
Posts: 51
Joined: Mon Mar 25, 2019 12:43 pm

Re: Getting OfObject attributes by name

Unread postby sam » Tue Feb 04, 2020 5:43 pm

Hi,

You could use set_string in some cases, but it's not robust since you can't use it to set arrays for example.

obj.get_attribute("unseen_by_camera").set_string("0")
or
obj.get_attribute("unseen_by_camera").set_string("1")

But I wouldn't recommend using this.
Sam Assadian
Isotropix
CEO/Founder
User avatar
sam
 
Posts: 1498
Joined: Fri Jan 25, 2013 11:33 pm

Re: Getting OfObject attributes by name

Unread postby briansilva » Wed Feb 05, 2020 10:53 am

Ah thanks for the tip Sam!

But I think I'll take your advice and be more robust about it -- I saw something in the clarisse_helper.py that checks for attribute type, I'll see if I can retrofit that.
briansilva
 
Posts: 51
Joined: Mon Mar 25, 2019 12:43 pm


Return to Scripting
cron