Isotropix Forums

Access custom alembic attributes?

Clarisse Scripting related topics

Access custom alembic attributes?

Unread postby dane » Sun Nov 03, 2019 4:11 pm

If I add a custom string attribute to geometry in Maya, then export as alembic (listing the attributes) can I access that information through python in Clarisse?

Thanks
dane
 
Posts: 98
Joined: Wed Aug 29, 2018 11:50 am

Re: Access custom alembic attributes?

Unread postby anemoff » Mon Nov 04, 2019 10:31 am

Hi,

Yes, you can use this script:

python code

def extract_string_property_values(geometry, prop_name):
"""
Extract values and indices from a string property of Geometry.
Returns a tuple: (values, indices)
"""

if not geometry:
return None, None
#print('[debug] geometry type: {}'.format(type(geometry.get_module()).__name__))

# search the property
collection = geometry.get_module().get_properties()
property = None
for i in range(collection.get_property_count()):
if collection.get_property(i).get_name() == prop_name:
property = collection.get_property(i)
break

if property:
#print('[debug] property type: {}'.format(type(property).__name__))
resource = property.get_values_property(0)
string = resource.get_string(0)
values = []
end = 0
for i in range(property.get_value_count()):
start = end
end = end + resource.get_item_value_count(i)
values.append(string[start:end])
ix.application.check_for_events()

indices = []
if type(property).__name__ != 'CurveMeshProperty':
# CurveMeshProperty doesn't support indexed values
indices = property.get_indices()
return values, indices
else:
ix.log_warning('Property {} not found.'.format(prop_name))
return None, None

# Usage example
geometry = ix.selection[0] # the geometry object
prop_name = 'foobar' # name of the property to read
(values, indices) = extract_string_property_values(geometry, prop_name)
if values and indices:
print('Geometry {}: property "{}" has {} values and {} indices.'.format(geometry.get_name(), prop_name, len(values), len(indices)))
for i in range(len(values)):
print '- value[%d] = "%s"' % (i, values[i])


Let me know if you need more help.
Cheers,
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 232
Joined: Wed Jan 13, 2016 10:10 am

Re: Access custom alembic attributes?

Unread postby dane » Tue Nov 05, 2019 11:11 am

Exactly what I was after! Thanks for that Anthony, appreciate it
dane
 
Posts: 98
Joined: Wed Aug 29, 2018 11:50 am

Re: Access custom alembic attributes?

Unread postby anemoff » Tue Nov 05, 2019 11:17 am

You're welcome!
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 232
Joined: Wed Jan 13, 2016 10:10 am

Re: Access custom alembic attributes?

Unread postby dane » Tue Nov 05, 2019 2:45 pm

Are we only able to read attributes from shape nodes on geometry (GeomertyAbcMesh)?

Is there a way of reading this from the abcXform?

Values exist on the group in maya for instance but that doesnt seem to pass through, not sure if its alembic not supporting it though

Thanks
dane
 
Posts: 98
Joined: Wed Aug 29, 2018 11:50 am

Re: Access custom alembic attributes?

Unread postby anemoff » Tue Nov 05, 2019 4:39 pm

Yes, this is a limitation of Clarisse.
There is only a special case for the visibility property, which is usually stored in direct parent xform of the geometry. But even in this case, this property is read internally and is not exposed. Therefore it cannot be extracted with an ExtractProperty for example.

I invite you to submit a feature request for this if you want.

A potential workaround is to create a companion point cloud that would contain a point with the desired property for each group from which you want to read. Instead of storing the property in the group (a group is translated as Locator in Clarisse), you would store it in a point of the point cloud (GeometryParticle in Clarisse, which can hold properties). Then you can extract the property with a classic ExtractProperty or with the script I give you if it's a string.
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 232
Joined: Wed Jan 13, 2016 10:10 am

Re: Access custom alembic attributes?

Unread postby dane » Tue Nov 05, 2019 5:28 pm

Okay just checking, all is fine, I can just store the properties on a hidden object within our mesh publish, alembic will write the visibility so it wont cause issues in clarisse!

Thanks again
dane
 
Posts: 98
Joined: Wed Aug 29, 2018 11:50 am


Return to Scripting