Add Python Scripting Component via Python Script

I have found python code to create rigdbodies, joints and most other components. But how can I add a Python Scripting Component to a prim via a python script?

Can you please guide me to the documentation?

https://docs.omniverse.nvidia.com/prod_extensions/prod_extensions/ext_python-scripting-component/user_manual.html

Hi @MartinBischoff

You can use kit commands to add a Python Scripting Component to a prim as follow:

import omni.usd
from pxr import Sdf

stage = omni.usd.get_context().get_stage()
prim = stage.GetPrimAtPath("/World")

# add the Python Scripting Component
prim_paths = [prim.GetPath()]
omni.kit.commands.execute("ApplyScriptingAPICommand", paths=prim_paths)
omni.kit.commands.execute("RefreshScriptingPropertyWindowCommand")

# add script
scripts = Sdf.AssetPathArray(["/home/toni/Documents/script.py"])
prim.GetAttribute("omni:scripting:scripts").Set(scripts)
1 Like

Thank you @toni.sm ! omni.kit.commands is what I was looking for.

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