Failure of USD Commands in Python


I’ve tried to use USD commands based on the following documents.

However, I found that the USD commands cannot be executed without any warnings and errors.

I have used “CopyPrimCommand” as an example in the following script. Copying prim has been executed with 3 different commands, i.e. “omni.usd.duplicate_prim”, “omni.usd.commands.CopyPrimCommand”, and “omni.kit.commands.execute”. The USD command doesn’t work.

The script I have used:
import omni.usd
import omni.usd.commands
import omni.kit.commands

orig_path = “/World/Acacia”
stage = omni.usd.get_context().get_stage()

print(“Copying start”)

omni.usd.duplicate_prim(stage=stage, prim_path=orig_path, path_to=orig_path+“_usd_dup”, duplicate_layers=False)
omni.usd.commands.CopyPrimCommand(path_from=orig_path, path_to=orig_path+“_usd_cmd”, duplicate_layers=False)
omni.kit.commands.execute(“CopyPrim”, path_from=orig_path, path_to=orig_path+“_kit_cmd”, duplicate_layers=False)

print(“Copying finished”)


Can anyone help? I’ve also tried the other USD commands in the document. They doesn’t work as well.

Thank you.

Hi @hippo_family. omni.kit.commands.execute is the correct way to call the command.

Creating an object of the command like you did in the second case does not execute the command. You need to call the do() function of the command object. You generally don’t want to do that though because it bypasses the Command history.

Hi @mati-nvidia

Thank you for your reply.

May I know more about the do() function? If I wanna use omni.usd.commands, another function is needed for it to execute? Since I can’t find any examples or information in the following document:
the following documents.

Thank you.

Yes. The omni.kit.commands framework is used to execute all Kit commands no matter which extension may register a command. More info here about omnil.kit.commands: Overview — omni.kit.commands 1.4.6 documentation

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