How can I move an object during simulation running?

I would like to move an object like a box.
I could set the initial position by below script.

import math
import omni
import omni.kit.commands
import omni.usd
from pxr import UsdGeom


def main(stage_path:str, x=0.0, y=0.0, z=0.0, roll=0.0, pitch=0.0, yaw=0.0):    
    stage = omni.usd.get_context().get_stage()

    obj = stage.GetPrimAtPath(stage_path)
    if obj.IsValid():
        obj_xform = UsdGeom.Xformable(obj)
        xform_ops = obj_xform.GetOrderedXformOps()

        obj_xform.ClearXformOpOrder()

        translate_op = obj_xform.AddTranslateOp()
        translate_op.Set((x, y, z))

        rotate_op = obj_xform.AddRotateXYZOp()
        rotate_op.Set((roll*180.0/math.pi, pitch*180.0/math.pi, yaw*180.0/math.pi))

But the object fly away when I run the script during simulation running.
How can I move an object during simulation running?

During simulation you should just edit the values, so for example:

translate_attr = prim.GetAttribute("xformOp:translate")
translate_attr.Set(...)

rotate_attr = prim.GetAttribute("xformOp:orient")
rotate_attr.Set(...)

Note that during simulation the rotation is in a quaternion form, xformOp:orient.

Regards,
Ales

Thanks to you, we have solved the problem.

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