Page 1 of 1

Determining whether a reference is an alembic or project

Unread postPosted: Thu Apr 29, 2021 6:59 am
by bvz
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?

Re: Determining whether a reference is an alembic or project

Unread postPosted: Thu Apr 29, 2021 9:28 am
by anemoff
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,

Re: Determining whether a reference is an alembic or project

Unread postPosted: Thu Apr 29, 2021 7:05 pm
by bvz
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.

Re: Determining whether a reference is an alembic or project

Unread postPosted: Thu Apr 29, 2021 7:20 pm
by sam
This is already what's happening internally. Everything is based on the actual supported extensions.