Extension Fundamentals

Hello

I’m going through some of the fundamentals around ui, spawning and manipulating objects in Omniverse. I’m using Omniverse Code to do this with VS Code.

Currently trying to solve how to get the currently selected prim(prim_path) so that i can use xformOp:scale etc to manipulate it.

If i run this it works but that is a static adress and not very useful:

class ScaleIncrementsNow(omni.kit.commands.Command):
        def __init__(self):
            stage = omni.usd.get_context().get_stage()
            prim = stage.GetPrimAtPath("/World/Cube")
            print(prim)
            prim.GetAttribute('xformOp:scale').Get()
            prim.GetAttribute('xformOp:scale').Set((2.0, 2.0, 2.0))
            

        def do(self):
            pass

        def undo(self):
            pass

Current resources i’m looking at: Get the Currently Selected Prims — Omniverse Developer Guide latest documentation

Update: Small success. I can now see a updated path for the current prim using the documentation. I can see it switching when switching prims. Now to manipulate it(grab it’s scale)

Updated class

    class ScaleIncrementsNow(omni.kit.commands.Command):
        def __init__(self):
            stage = omni.usd.get_context().get_stage()
            prim_path = "/World/My/Prim"
            ctx = omni.usd.get_context()
            selection = ctx.get_selection().get_selected_prim_paths()
            print(selection)
           

        def do(self):
            pass

        def undo(self):
            pass

Created a button to execute

def on_primselect(primselect):
                    omni.kit.commands.execute(primselect)
...
 ui.Button("Print selected Prim", clicked_fn=lambda: on_primselect('ScaleIncrementsNow'))

Current resources i’m looking at:

Found this: Display Object Info — Omniverse Workflows latest documentation

Progress report:

image

Managed to get a hold of the object and displaying it’s properties. Right now however it will not be destroyed when deselecting the prim. And it only stays at 0,0,0. Need to work on that.

Still getting this error though:

2024-01-25 13:18:42  [Error] [carb.events.python] TypeError: The value of type <class 'list'> can be converted to neither string nor AbstractManipulatorItem

Still following this resource: Display Object Info — Omniverse Workflows latest documentation

Stuck on errors:
Update: Restarted Code and only one error left.

2024-01-25 16:22:31  [Error] [omni.ui.scene.python] ArgumentError: Python argument types in
2024-01-25 16:22:31  [Error] [omni.ui.scene.python]     BBoxCache.__init__(BBoxCache, TimeCode)
2024-01-25 16:22:31  [Error] [omni.ui.scene.python] did not match C++ signature:
2024-01-25 16:22:31  [Error] [omni.ui.scene.python]     __init__(struct _object * __ptr64, class pxrInternal_v0_22__pxrReserved__::UsdTimeCode time, class std::vector<class pxrInternal_v0_22__pxrReserved__::TfToken,class std::allocator<class pxrInternal_v0_22__pxrReserved__::TfToken> > includedPurposes)
2024-01-25 16:22:31  [Error] [omni.ui.scene.python]     __init__(struct _object * __ptr64, class pxrInternal_v0_22__pxrReserved__::UsdTimeCode time, class std::vector<class pxrInternal_v0_22__pxrReserved__::TfToken,class std::allocator<class pxrInternal_v0_22__pxrReserved__::TfToken> > includedPurposes, bool useExtentsHint)
2024-01-25 16:22:31  [Error] [omni.ui.scene.python]     __init__(struct _object * __ptr64, class pxrInternal_v0_22__pxrReserved__::UsdTimeCode time, class std::vector<class pxrInternal_v0_22__pxrReserved__::TfToken,class std::allocator<class pxrInternal_v0_22__pxrReserved__::TfToken> > includedPurposes, bool useExtentsHint, bool ignoreVisibility)

I feel like this line is incorrect somehow:

box_cache = UsdGeom.BBoxCache(Usd.TimeCode.Default(), includePurposes=[UsdGeom.Tokens.default_])

Comparing with the code here: kit-extension-sample-ui-scene/exts/omni.example.ui_scene.object_info/Tutorial/Final Scripts/object_info_model.py at main · NVIDIA-Omniverse/kit-extension-sample-ui-scene · GitHub

It’s the same. I fixed one error that was a typo of mine.

Tried comparing again the codes.
Using the example code gives a working extension:
bild

Trying to figure out what is wrong with my script.

FOUND IT!

I had omitted the d in included. Works now.

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