CollectionAPI membership query question

Hi all,

I have a collection with an expression and I’m trying to detect when I remove an object from the stage if it matches the collection expression.
Apparently it doesn’t work because the implementation tries to get the object from the stage before matching the path:

Is there any reason for this or is it a bug?
If it’s intended, is there another way to achieve it?

Thanks!

It is intentional, and necessary in general, due to the potential presence of predicate functions in the membership expression.

If you know the collection is expression-based and you fetch the resolved expression using UsdCollectionAPI::ResolveCompleteMembershipExpression(), then if you also can guarantee there are no predicate functions, then you should be able to construct and use a SdfExpressionEval<SdfPath> with an empty predicate library, directly. Alex says, that if there are predicate functions, the best you could do is make it behave as if all predicate expressions are true , by processing the resolved expression by writing a transformer using SdfPathExpression::Walk() to reconstitute a new path expression that strips all predicate expressions but is otherwise the same.

Then feed that result to SdfExpressionEval.

Cheers,
–spiff

Ok I see, it makes sense. Yes I guess I can try to change the expression then because it’s fine if I end up with false positives.

Thanks a lot!
Nico