How Can I add object with another python script?

Hello,

I run simulation_app as a standalone application like the one below.
https://docs.omniverse.nvidia.com/isaacsim/latest/core_api_tutorials/tutorial_core_hello_world.html#converting-the-example-to-a-standalone-application

I’m trying to add objects with another Python script because I want to add objects dynamically and automatically.

For example, I tried REPL with the below script. But this script cannot generate new object.

from telnetlib import Telnet
import time

def main():
    print("Start")
    with Telnet("127.0.0.1", 8223) as tn:
        print("Connected")
        print(tn.read_until(b">>>", timeout=1))
        tn.write(b"import omni.kit.commands\n")
        print(tn.read_until(b">>>", timeout=0.1))
        tn.write(b"omni.kit.commands.execute('CreateMeshPrimWithDefaultXform', prim_type='Cube')\n")
        print(tn.read_until(b">>>", timeout=10))

if __name__ == '__main__':
    main()

I get below log.

Start
Connected
Telnet(127.0.0.1,8223): recv b'\xff\xfd"\xff\xfb\x03'
Telnet(127.0.0.1,8223): IAC DO 34
Telnet(127.0.0.1,8223): IAC WILL 3
Telnet(127.0.0.1,8223): recv b'\xff\xfa"\x01\x00\xff\xf0\xff\xfb\x01\xff\xfd\x1f\xff\xfd\x18\xff\xfa\x18\x01\xff\xf0'
Telnet(127.0.0.1,8223): IAC 250 not recognized
Telnet(127.0.0.1,8223): IAC 240 not recognized
Telnet(127.0.0.1,8223): IAC WILL 1
Telnet(127.0.0.1,8223): IAC DO 31
Telnet(127.0.0.1,8223): IAC DO 24
Telnet(127.0.0.1,8223): IAC 250 not recognized
Telnet(127.0.0.1,8223): IAC 240 not recognized
b''
Telnet(127.0.0.1,8223): send b'import omni.kit.commands\n'
b''
Telnet(127.0.0.1,8223): send b"omni.kit.commands.execute('CreateMeshPrimWithDefaultXform', prim_type='Cube')\n"
b''

The way with “telnet localhost 8223” and using below commands is worked.

>>> import omni.kit.commands
>>> omni.kit.commands.execute('CreateMeshPrimWithDefaultXform', prim_type='Cube')

So, the REPL extension is enabled.

How can I add object with another python script?

Thank you.

I solved this problem with below bash command.

(sleep 1; echo -e ' import omni.kit.commands\nomni.kit.commands.execute('CreateMeshPrimWithDefaultXform', prim_type='Cube')\n'; sleep 5) | telnet localhost 8223

Eventually, I integrated this technique into a Python script to be able to import arbitrary URDFs.

1 Like

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