Isotropix Forums

List object attributes

Clarisse Scripting related topics

List object attributes

Unread postby nico » Tue May 30, 2017 6:14 pm

Hi there,

Perhaps I'm missing something obvious, but how would I best go about getting all attributes a specific object has?

What I roughly have now:

python code

objects = ix.selection
for o in objects:
material = o.attrs.materials[0]
print(o.attrs) # This won't work as I imagine it would


That last line returns:
Code: Select all
<framework.OfAttrs; proxy of <Swig Object of type 'OfAttrs *' at 0x000000000A6F4F30> >

Which is all fine, but then I look in the documentation, and 'OfAttrs' isn't directly defined there as a class. Only 'OfAttr'(or should I look at 'OfAttrPtr'?)

Long story short, I'm looking for a way I can list all attributes on an Clarisse-object.

dir(material) obviously gives me a list of members, but the attributes are stored in .attrs right?
I can't seem to list/dir/print that.

Thank you for your time and consideration!
nico
 
Posts: 4
Joined: Fri Nov 04, 2016 12:34 pm

Re: List object attributes

Unread postby bvaldes » Wed May 31, 2017 9:20 am

Hi,

Clarisse does not return python "readable" things. That mean that when you print ix.selection, you will not have ['item1', 'item2', 'item3'...]. Instead, you will have a custom object (like class in python) like you get for attributes.
You can check that by using: print type(ix.selection).

To achieve what you want you can do something like this:

python code

selection = ix.selection # This is our selection, it contains item but it is not a python list, this is a custom C++ Array
for i in range(selection.get_count()): # selection.get_count() gives you the number of items inside the array
item = selection[i] # This is our item, we get it like we could get it inside of a python list
print str(item)+":" # You can remove this line it's just to get a feedback
for j in range(item.get_attribute_count()): # item.get_attribute_count() gives us the number of attributes for this item
attr = item.get_attribute(j) # This is our attribute, we get it like we could get it inside of a python list
print " "+str(attr) # You can remove this line it's just to get a feedback

Regards
Benoit VALDES
Isotropix
Clarisse QA
User avatar
bvaldes
 
Posts: 117
Joined: Mon Sep 26, 2016 11:44 am

Re: List object attributes

Unread postby nico » Thu Jun 01, 2017 2:36 pm

Thank you very much!

Apparently I still need to get accustomed to coding in Clarisse. :lol:

As I go along I'm trying to create a few of my own helper functions, so this gets added to the list!

python code

def list_attributes(obj, full_name=True):
"""
Returns a list with all the attributes (as <CoreString> objects) of the given Clarisse Object.

Example returns:
full_name=True: ["project://scene/diffuse1.normal_mode", ..]
full_name=False: ["normal_mode", ..]
"""
ret = []
for i in range(obj.get_attribute_count()):
attr = obj.get_attribute(i)
if attr:
if full_name:
ret.append(attr.get_full_name())
else:
ret.append(attr.get_name())
return ret
nico
 
Posts: 4
Joined: Fri Nov 04, 2016 12:34 pm


Return to Scripting