KIT: Execute Command script failing

I am trying to execute the Snippet in Snippets > Commands > Execute Command in the Kit Script Editor:

import omni.kit.commands

omni.kit.commands.execute("CreatePrimCommand", prim_type="Sphere")

And get the following error

2021-01-07 07:16:11  [Error] [carb.python] Failed to execute a command: CreatePrimCommand.
  File "executing: Python 0...", line 3, in <module>
  File "c:\users\rustr\appdata\local\ov\pkg\kit 100.1.0\_exts\omni.kit.commands\omni\kit\commands\", line 177, in execute
    return omni.kit.undo.execute(command, name, kwargs)
  File "c:\users\rustr\appdata\local\ov\pkg\kit 100.1.0\_exts\omni.kit.commands\omni\kit\undo\", line 74, in execute
    result = _execute(command, name, level, history_key)
  File "c:\users\rustr\appdata\local\ov\pkg\kit 100.1.0\_exts\omni.kit.commands\omni\kit\undo\", line 314, in _execute
    raise e

 <class 'UnboundLocalError'> local variable 'e' referenced before assignment

Any ideas why this is happening?
Thank you

Thank you for using Omniverse. Are you are just trying to create a prim (sphere) that can be displayed on the viewport? Looking for some background on your intent.

Not sure why that command is failing (we’ll take a look), but you probably want to use CreatePrimWithDefaultXformCommand.

A nice trick is to use the Command Utils extension to inspect and capture commands you are executing as you use the Kit UI. You can enable this extension from Extensions window:

Once enabled, you can open up the Commands window:

Any commands you’ve executed (e.g. Create/Sphere) will show up in the command stack in this window. You can copy specific commands or the whole command stack as Python that’s executable in the script editor to your clipboard:

The Create/Sphere UI function produces this command:

    import omni.kit.commands

    	attributes={'radius': 50, 'extent': [(-50, -50, -50), (50, 50, 50)]})

You can paste that into the script editor and execute.

I tried to reproduce your problem, but it is executing for me correctly. Can you take a screenshot of the failure with the console window showing?

The scripting that you have problems with happens since you are using “Kit”. Kit requires additional scripting to build the infra needed to create prims. If you use “Create”, that infra is already present. Use the steps outlined in the previous response from @revl.

1 Like

Hi revl and mirice,

Thank you very much for your swift replies!
Indeed, as soon as I switched to using the script editor in Create everything was working just fine.

Best regards