How to rename a prim programmatically

Hello, I’m trying to rename a list of prims in a usd scene with Python script, but having trouble finding the correct method to use. Any help would be appreciated, thank you!

omni.kit.commands “MovePrim” from this post can do it if I just specify the same path before and after, but I’m wondering if there is a more straightforward method like “Rename” or “Refactor”.

Hello @Sirikk! Welcome to the Community! I’ll connect you with a developer to get some help!

I don’t quit understand what you mean about “can do it if I just specify the same path before and after”. Do you mean you can only specify path_to as the sibling node as the one you want to move? MovePrim command could support to move prim to other parent also. One thing to mention is that you need to make sure the parent of the target path is existed before move, otherwise, it will be created as al overso render will not populate it for rendering, like:

omni.kit.commands.execute("MovePrim", path_from=FROM_PATH, path_to=TARGET_PATH)

It may be similar to the “mv” manner of Linux.
It seems to be possible to rename “test” to “test2” as follows.

path = “/World/test”
pathTo = “/World/test2”
omni.kit.commands.execute(“MovePrim”, path_from=path, path_to=pathTo)

For omni.kit.commands.execute, you can track its history in the Commands window of Omniverse Code.
Omniverse Code is handy!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.