Spawn mesh into scene and set its location and rotation

I would like to spawn a mesh into Create and then modify its location and rotation. This can be done with or without physics. Documentation only seems to show primitive spawning.

Is this what you’re looking for?

No, I would like to spawn and move an object using python. Essentially, I would need to spawn a mesh, then animate its location using python. The solution can be with or without the use of physics.

What kind of mesh do you want to spawn? It’s the simple primitives (like cube) Create provided? Or your own USD?

If you already know the object path, you can get the object (prim in USD), like

import omni.usd
“”“This will get the stage handle opened in the editor.”""
stage = omni.usd.get_context().get_stage()
prim = stage.GetPrimAtPath(YOUR_SPAWNED_OBJECT_PATH)

Then you can refer extention for how to register update event to call your update function per frame. And operate your object with USD API to animate your object.

Hope this helps. We’ll keep improving the documentation to provide more programming samples.

If you are emptempting to create a new prim from an usd file, I am no expert but this is how i do it:

from omni.usd import Usd, UsdGeom, Sdf, Gf, get_context

# Get your stage and your current layer
stage = get_context().get_stage()
layer = stage.GetEditTarget().GetLayer()

# Get your parent
parent = layer.GetPrimAtPath(Sdf.Path('/World/your/parent_prim'))

# Create a new prim with reference
model_spec = Sdf.PrimSpec(parent, 'new_prim_name', Sdf.SpecifierDef)
my_new_prim = stage.GetPrimAtPath('/World/your/parent_prim/new_prim_name')

# Create tranform, rotate, scale attributes
properties = my_new_prim.GetPropertyNames()
if 'xformOp:translate' not in properties:
if 'xformOp:rotateZYX' not in properties:
if 'xformOp:scale' not in properties:

# Set your tranform, rotate, scale attributes
my_new_prim.GetAttribute('xformOp:rotateZYX').Set(Gf.Vec3f(1.0, 2.0, 4.0))
my_new_prim.GetAttribute('xformOp:rotateZYX').Set(Gf.Vec3f(0.0, 0.0, 90.0))
my_new_prim.GetAttribute('xformOp:scale').Set(Gf.Vec3f(1.0, 1.0, 1.0))

As for animating it, I dont know. Hope it helps.