get collections from selected prim with python

   4508   4   2
User Avatar
Member
260 posts
Joined: Nov. 2014
Offline
Hello guys.
Im running into issue how to get list of collections with python, my selected prim lives.

There is no indication in Details on that prim (like we had in SOPs with groups).

I can see one possible solution would be to loop over each collection and check if my selected prim lives inside. Which might be slow on heavy scenes. But even with this scenario, im struggling to find relevant documentation.



Ideas?
User Avatar
Staff
4447 posts
Joined: July 2005
Offline
Collections in USD are stored as essentially a list of paths to the members of that collection. There is no "back pointer" from the prims to the collections that contain them. So the only way to do this is to find all collections and look for you prim in the members of that collection. Standard USD python APIs can be used for this purpose.
User Avatar
Member
260 posts
Joined: Nov. 2014
Offline
Thank you for your fast reply.

I have checked the USD CollectionAPI and its what im after.

Any chance you would be able to provide me with sample code using CollectionAPI?
Im not able to make it work on my own, but im able to understand the syntax from the example and extend it to what i need at the end.

Like you helped me with my previous question?
User Avatar
Staff
4177 posts
Joined: Sept. 2007
Offline
The unit tests on Github have a lot of really good examples for the Python API: https://github.com/PixarAnimationStudios/USD/blob/v21.08/pxr/usd/usd/testenv/testUsdCollectionAPI.py [github.com]

As does Colin Kennedy's website: https://github.com/ColinKennedy/USD-Cookbook [github.com]
I'm o.d.d.
User Avatar
Member
260 posts
Joined: Nov. 2014
Offline
goldleaf
The unit tests on Github have a lot of really good examples for the Python API: https://github.com/PixarAnimationStudios/USD/blob/v21.08/pxr/usd/usd/testenv/testUsdCollectionAPI.py [github.com]

As does Colin Kennedy's website: https://github.com/ColinKennedy/USD-Cookbook [github.com]
thats awesome
i was googling for several days before asking here.
but never found those.
they are really handy
  • Quick Links