Reparent a Prim under another Prim

I am trying to find a way to reparent a prim under another prim in a loaded stage. Basically, I want to insert a new Xform in the middle of the hierarchy, so I am trying to define the new Prim and the reparent all the children under the new Prim, but I cannot find any function to reparent a prim with the python API.
Is there a way to do it? If it’s not in Python, is there a way in C++ to do it?

Thanks a lot!

Hi @diegogarces ! Can I ask:

  1. What version of USD are you using?
  2. Are all the prims in question in a single layerStack, or are some of them defined in “remote” layers and brought in by reference/payload etc?

And I ask because in USD 24.05 you can, in python, create a Usd.NamespaceEditor object for your stage that will allow you to reparent, move, and rename prims defined in any layer of your root layerStack. And soon, that “root layerStack” restriction will be lifted.


Thanks a lot spiff!
I am using blender 4.1 which contains USD 23.11 and all the prims are in the root layer, it’s a pretty simple case.
Is there a way to do those operations in that version of USD?

Thanks a lot!

Hi @diegogarces , in usdtweak reparenting can be done at the layer level, and it works with older versions of usd. If you are looking for an example it’s implemented here : usdtweak/src/commands/PrimCommands.cpp at b5d34771941d3aaa040b24f247f5e563b1417e9b · cpichard/usdtweak · GitHub

If you are using USD/Hydra 2.0 with scene indices (instead of scene delegates), there is a scene index named “UsdImagingRootOverridesSceneIndex” which has been designed to add a transform and visibility attributes which will propagate to all prims from another child scene index.

Potentially these code snippets in usd-qtpy here may guide you along:

Note that these will start changing PrimSpec opinions across the layers, and hence may influence many layers - potentially spanning across layers, references, payloads, etc.

More details on Editing Prim Specs where answered on the forum here and in the past I’ve faced some issues with batch namespace edits in variant sets which you may be useful background info if you run into crashes.

Thanks a lot everyone!
Cyril example was perfect for what I was trying to do. It worked like a charm.

I really appreciate the help!