How to turn on/off the light or object in Omniverse Creat or sim

Hi @gudwnzm

You can program for any omniverse App as long as you use generic code, for example from the Omniverse Kit API as used in the code above. Now, if you want to use robotic specific extensions for simulation, you are restricted to Isaac Sim.

Regarding how to program, there are different ways such as Omniverse extensions, apps, or microservices. I recommend you take a look at Omniverse Code

I really appreciate your kindness.
I will take a look at Omniverse Code!
Lastly… I have the last question…
The last question is that I have many SphereLights.
So I created the Xform as a parent which has many SphereLights like a bundle.
When I press the space bar on keyboard, the visibility of Xform is on and off…
I want to turn it on and off with only one xform which has many SphereLights.
I hope you understand what I’m saying.
please help me one last time…

For example…

import carb
import omni
from pxr import Usd, UsdGeom
import omni.usd

# get prim and its attribute ("intensity")
stage = omni.usd.get_context().get_stage()
prim = stage.GetPrimAtPath("/World/lamp/Looks/lamp_bundle")
attribute = prim.GetAttribute("visibility")

def keyboard_event(event, *args, **kwargs):
    if event.type == carb.input.KeyboardEventType.KEY_PRESS:
        if event.input == carb.input.KeyboardInput.SPACE:
            attribute.Set(inherited if attribute.Get() else invisible)  # change attribute
# subscribe to keyboard event
appwindow = omni.appwindow.get_default_app_window()
input = carb.input.acquire_input_interface()
input.subscribe_to_keyboard_events(appwindow.get_keyboard(), keyboard_event)

Hi @gudwnzm

The visibility attribute type is str

Then if you want to toggle it you can try something like this

attribute.Set("inherited" if attribute.Get() == "invisible" else "invisible")

Thank you for your response and your kind words.
It really works well… Thank you
where could I refer to those API like attribute.Set, Get??
I have tried to find those API which means properties of Get or Set In the link below but I could not make it…, Universal Scene Description: UsdGeomXform Class Reference, pxr package — kit-sdk 103.1 documentation

I’d like to use various keyboard_events not only for space bar like enter, WASD and number 1 etc…
So I need to refer to API of keyboard_events as well…

Thank you so much for your help.

Omniverse Kit Programming: Kit Programming Manual — kit-sdk 103.1 documentation

I really appreciate all your kindness.
It works very well now.
I will take a look at Omniverse Code hardly following your advice.

Glad to help 😁.

By the way, very nice job with the lights

I’m sorry, but I have one last question.
How would I run my python code which wrote from VScode in Omniverse isaac-sim?
I usually code and run it from Script Editor in Omniverse isaac-sim
However, If I run it once from Script Editor and I want to edit some code, I should starts Omniverse isaac-sim again.
Nothing has changed…
So I’d like to edit code my heart’s content.
How could I apply my code which coded from VScode to Omniverse isaac-sim?
Even though I have take a look at Omniverse Code, I could not find about that…

Hi, @gudwnzm

You can write your code in a user extension (and optionally enable its autoload) or program a standalone application…

The files are good starting point:


  • PATH_TO_ISAAC_SIM/kit/exts/omni.example.hello

standalone app

  • PATH_TO_ISAAC_SIM/standalone_examples/api/omni.isaac.kit/
  • PATH_TO_ISAAC_SIM/standalone_examples/api/omni.isaac.kit/

It’s a different story from the topic of this article, but I’m asking because there’s no one to ask.
Is there a way to see the model created by Omniverse Create in oculus quest 2 through Omniverse CloudXR?
If you know how to do it, please tell me. please
Always Thank you!

Hi @gudwnzm

As a user, I only know this reference to CloudXR in Omniverse (Augmented Reality — Omniverse Create documentation) for “modern Android or iOS mobile device capable of running AR applications”

There is the external user extension (omni.add_on.openxr) that supports XR in any Omniverse application (Isaac Sim, Create, etc. running on Linux, at the moment). I have only tested it with a HTC Vive Pro 2 (it is the only device to which I have access) although it is designed to work with any device that supports the OpenXR standard.

Thank you for your response to CloudXR.
I’m so sorry to ask you again, but would I ask for a good example just like last time?
I’m still studying the USD library, but I’m a developer of Unity, so there’s still a lot of confusion. I want to control the door in the video I showed you above with a keyboard.
I want to click on keyboard P to make a toggle key that goes up and down the door. I really see and realize a lot through you.
I am collecting and organizing the materials you help and making them into learning materials. I also want to share this with people later and help people like you.
Please help me again.

Hi @gudwnzm

You can do it from different approaches, for example: editing the attributes of a prim and modifying its transformations or involving physics, through rigid bodies, joints (prismatic joint) and articulations (dynamic_control extension). While the former is simpler, the latter is more natural…

Here is a snippet that shows both approaches in a scenario with two doors: left (prim attr) and right (dynamic_control). Look inside the .usd to inspect the rigid bodies, the articulation and the joint

door.usd (4.5 KB)

import pxr
import carb
import omni
import omni.usd
from omni.isaac.dynamic_control import _dynamic_control

opened = False

# left door (prim attributes)
stage = omni.usd.get_context().get_stage()
left_door = stage.GetPrimAtPath("/World/left_door/door")

# right door (articulation)
dc = _dynamic_control.acquire_dynamic_control_interface()
ar = dc.get_articulation("/World/right_door")
dof = dc.get_articulation_dof(ar, 0)

def keyboard_event(event, *args, **kwargs):
    global opened

    if event.type == carb.input.KeyboardEventType.KEY_PRESS:
        if event.input == carb.input.KeyboardInput.P:
            # close
            if opened:
                dc.set_dof_position_target(dof, 0)
            # open
                dc.set_dof_position_target(dof, 195)
            opened = not opened
# subscribe to keyboard event
appwindow = omni.appwindow.get_default_app_window()
input = carb.input.acquire_input_interface()
input.subscribe_to_keyboard_events(appwindow.get_keyboard(), keyboard_event)

I’d really like to say thank you for replying me!
I have tried the example which you wrote it.
But there is a small problem…

Above picture is made by Omniverse Create
It says that NameError: name’_dynamic_control’ is not defined, ModuleNotFoundError: No module named ‘omni.isaac’
So I think dynamic_control is available on Isaac sim
Is there any way to control physics API like dynamic_control in Omniverse Create?

And I’d tried to run in Isaac sim Sim
But there is other problem…

Thank you so much for always helping me.


I’m sorry, but I’m sorry that you’re the only one to ask, but I have one more question. I used the extension manager to turn on the light that I coded last time at in VSCode.
It says that [Error][carb.input.python]NameError:name’attribute’is not defined in VSCode. There’s no problem when you look at the code.
If I use the same code in Scripteditor in Omniverse window, it runs, but VScode says the attribute is not defined.
Did I miss anything?

Hi @gudwnzm

Please, open a new topic if the problem is not directly related to the original topic of this post, in order to better organize the content :)

Yes, dynamic_control is an Isaac Sim extension. What about using prim methods to change the drive:linear:physics:targetPosition (Target Position) attribute’s value?

Make sure the simulation is running before calling the code

You are trying to get an attribute of a prim (that is created as a Python class variable)). This prim will be initialized when the extension is loaded by the extension manager (even if your USD scene is not currently loaded) resulting in an invalid prim (because the path does not exist). Instantiate your prim and its attribute using another logic, for example inside a button callback…

I didn’t know I had to open a new topic. I’ll do that from next time. Thank you so much for always helping me.
Lastly in this topic… Would I ask what inside a button callback is?

Do you mean this button callback?

As you said, instead of the button callback function, I put the code on and off the light.
NameError: name ‘attribute’ is not defined error does not change.


Otherwise, is there a way to use the code you created, that is, create as a Python class variable, in the extension manager?

Hi @gudwnzm

Special attention must be taken when instantiating the attribute. As you are working inside an extension (which is automatically reloaded by the extension manager when it is modified), the attribute, instantiated outside the keyboard event (which may not have been destroyed) no longer exists after the hot loading…

A possible solution would be to instantiate the variable when required if it does not exist.

class Extension(omni.ext.IExt):
    def on_startup(self):

        # subscribe to keyboard event
        self._input = carb.input.acquire_input_interface()
        self._keyboard = omni.appwindow.get_default_app_window().get_keyboard()
        self._sub_keyboard = self._input.subscribe_to_keyboard_events(self._keyboard, self.keyboard_event) 

    def keyboard_event(self, event, *args, **kwargs):
        if event.type == carb.input.KeyboardEventType.KEY_PRESS:
            if event.input == carb.input.KeyboardInput.P:

                if not hasattr(self, "attribute"):
                    stage = omni.usd.get_context().get_stage()
                    prim = stage.GetPrimAtPath("/World/LightPivot_01")
                    self.attribute = prim.GetAttribute("visibility")
                self.attribute.Set("inherited" if self.attribute.Get() == "invisible" else "invisible")  # change attribute

    def on_shutdown(self):
        self._input.unsubscribe_to_keyboard_events(self._keyboard, self._sub_keyboard)
        self._input = None
        self._keyboard = None
        self._sub_keyboard = None

The idea of the button callback would allow you to initialize some components of your simulation only on user request and not when the extension is loaded by the extension manager, since the scenario, on which your code works, may not have been loaded yet

1 Like

Thank you so much for your kind help all the time.
Now, I will finish this topic and open a new topic if I have any questions.
Thank you always.

Glad to help :)