Search - User list
Full Version: How to rename/remove/reparent prims with Python?
Root » Solaris and Karma » How to rename/remove/reparent prims with Python?
alexmajewski
How to do what Restructure Scene Graph LOP does, but with Python?
goldleaf
That node is currently implemented in Python, you can look inside and learn from it. There are also unit tests on the OpenUSD GitHub repo, that are written in Python that use Sdf Changeblocks and do some of these same editing operations.
alexmajewski
Thanks goldleaf I did like you said with full success.

If anyone finds this post in the future, here's a minimal example of reparenting a prim (it requires the layer to be flattened first):
from pxr import Sdf
node = hou.pwd()
layer = node.editableLayer()

cube_path = Sdf.Path("/Cube")
new_cube_path = Sdf.Path("/Objects/Cube")

edit = Sdf.BatchNamespaceEdit()
edit.Add(cube_path, new_cube_path)
    
if not layer.Apply(edit):
    raise Exception("Failed to apply layer edit!")
And to my understanding, if we plan to make more operations, we should add with Sdf.ChangeBlock():before the edit = Sdf.BatchNamespaceEdit()
Other ways and examples on reparenting, renaming or removing can be found in the USD Survival Guide, here. [lucascheller.github.io]
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB