Import my.custom.extension in another custom extension

Hi there, I am following the documentation here:
https://docs.omniverse.nvidia.com/kit/docs/kit-manual/latest/guide/extensions_advanced.html

I am trying to import a custom extension into another custom extension. Following the totorial:
say my extension A has in its .toml file:
image

and my extension B has in its .toml file:
image

this only enables extension A (when I enable extension B). I cannot actually import the extension
image

thank you

Hey Daniel,

import omni.ext
from typing import Optional

_extension_instance = None


class LbenhorinHelloWorldExtension(omni.ext.IExt):
    # ext_id is current extension id. It can be used with extension manager to query additional information, like where
    # this extension is located on filesystem.
    def on_startup(self, ext_id):
        global _extension_instance
        _extension_instance = self
        print("[lbenhorin.hello.world] lbenhorin hello world startup")
        pass

    def on_shutdown(self):
        global _extension_instance
        _extension_instance = None
        print("[lbenhorin.hello.world] lbenhorin hello world shutdown")


def get_instance() -> Optional[LbenhorinHelloWorldExtension]:
    return _extension_instance

You can check this code, this extension is holding a reference to itself, which can be imported from other extensions (considering it is actually loaded)

Hope this helps!

@lbenhorin thank you for your responce. I guess I didnt explain the issue well enough, please notice the following error:
image
image

This error accurse because the files of extension A (which has the module name camera.parameters.demo) are not in the folder of extension B.

Of course, adding a singleton object to extension A does not solve the Import error.

image

Thank you,
Danielle

If you refer to the Pylance warning - Then this is PATH issue, but when you will execute the code inside omniverse this should work.
I think that to get this error gone and have code completion then you will have to edit the .vscode/settings.json file with your extension.

Hope this makes sense

Awesome, works perfectly. Thank you

1 Like

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