Isotropix Forums

Determining whether a reference is an alembic or project

Clarisse Scripting related topics

Determining whether a reference is an alembic or project

Unread postby bvz » Thu Apr 29, 2021 6:59 am

I frequently have to determine whether a context is a referenced alembic file or a referenced clarisse project.

The way I have been doing this up till now is to:

a) Check that the item is a context
b) Then check to see if it is a reference
c) Then check the filename attribute to see if it ends in .abc or .project


This seems like it is not too clean and could suffer from edge cases (missing file name in the attribute for example). Is there a better way to do this?
bvz
 
Posts: 100
Joined: Tue Dec 03, 2013 9:55 am

Re: Determining whether a reference is an alembic or project

Unread postby anemoff » Thu Apr 29, 2021 9:28 am

That's the way to go. The context engine is the same in both cases: OfFileReferenceContextEngine. So the file extension is the only difference.
If the filename attribute is empty the context engine is still an OfFileReferenceContextEngine.
There's no built-in API to query such information at the moment.

Can you think of other edge cases that could cause problems with this method?

Cheers,
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 421
Joined: Wed Jan 13, 2016 10:10 am

Re: Determining whether a reference is an alembic or project

Unread postby bvz » Thu Apr 29, 2021 7:05 pm

Mostly missing file names or incorrect file names. Probably not a big deal.

I have a tool that swaps alembic references to alembic bundles and back again. Obviously I do not want it to operate on reference types other than alembic. (I will probably do the same with USD references).

I use the above tests to make sure I am not trying to operate on a non-alembic reference, but if the file name field is either empty or is somehow loading an incorrect file type it will not work.

That said, it is not really a big deal. It just skips over those at the moment. But I was wondering whether there was a better way and it looks like I am doing it correctly.

The only other edge case that I can think of is if an expression is on the file name attribute of one of these references. Again, not a likely or even big issue.
bvz
 
Posts: 100
Joined: Tue Dec 03, 2013 9:55 am

Re: Determining whether a reference is an alembic or project

Unread postby sam » Thu Apr 29, 2021 7:20 pm

This is already what's happening internally. Everything is based on the actual supported extensions.
Sam Assadian
Isotropix
CEO/Founder
User avatar
sam
 
Posts: 1719
Joined: Fri Jan 25, 2013 11:33 pm


Return to Scripting