How to get value from SimpleFloatModel

Hi, I’m working on developing an extension.

I’m having trouble implementing the Transformation UI.

Below is the code for the Transformation UI and a picture of the UI from the extension.

    def _robot_transformation_frame(self):
        properties = ["Translate", "Orient", "Scale"]
        axis = ["X", "Y", "Z"]
        colors = {"X": 0xFF5555AA, "Y": 0xFF76A371, "Z": 0xFFA07D4F}

        with ui.VStack(spacing=8):
            ui.Spacer(height=0)

            for _property in properties:
                with ui.HStack():
                    with ui.HStack():
                        ui.Label(_property, name="Transformation", width=50)
                        ui.Spacer()

                    for ax in axis:
                        default_value = 0.0 if _property in ["Translate", "Orient"] else 1.0
                        with ui.HStack():
                            with ui.ZStack(width=15):
                                ui.Rectangle(width=15, height=20, style={
                                    "background_color": colors[ax],
                                    "border_radius": 3,
                                    "corner_flag": ui.CornerFlag.LEFT,
                                })
                                ui.Label(ax, name='transform_label', alignment=ui.Alignment.CENTER)

                            float_drag = ui.FloatDrag(name=_property, min=-1000000, max=1000000, step=0.01)
                            float_drag.model.set_value(default_value)
                            self._robot_transform_models.append(float_drag.model)

            ui.Spacer(height=0)

            ui.Button(
                "Apply Transform",
                height=50,
                clicked_fn = self._apply_transform_callback,
                style=BUTTON_BASE_STYLE)
        
            ui.Button(
                "Reset Transform",
                height=50,
                clicked_fn = self._reset_transform_callback,
                style=BUTTON_BASE_STYLE)
                    

    def _apply_transform_callback(self):
        # translate = Gf.Vec3d(
        #     self._robot_transform_models[0],
        #     self._robot_transform_models[1],
        #     self._robot_transform_models[2]
        # )
        # rotate = Gf.Vec3d(
        #     self._robot_transform_models[3],
        #     self._robot_transform_models[4],
        #     self._robot_transform_models[5]
        # )
        # scale = Gf.Vec3d(
        #     self._robot_transform_models[6],
        #     self._robot_transform_models[7],
        #     self._robot_transform_models[8]
        # )
        translate = (
            self._robot_transform_models[0],
            self._robot_transform_models[1],
            self._robot_transform_models[2]
        )
        rotate = (
            self._robot_transform_models[3],
            self._robot_transform_models[4],
            self._robot_transform_models[5]
        )
        scale = (
            self._robot_transform_models[6],
            self._robot_transform_models[7],
            self._robot_transform_models[8]
        )
        print(f"Applying transform: Translate={translate}, Rotate={rotate}, Scale={scale}")
        self.robot_importer._apply_transform(translate, rotate, scale)


    def _apply_transform(self, translate, orient, scale):
        stage = omni.usd.get_context().get_stage()
        prim = stage.GetPrimAtPath(self._get_prim_path())

        if prim.IsValid():
            xform = UsdGeom.XformCommonAPI(prim)
            xform.SetTranslate(translate)
            xform.SetRotate(Gf.Vec3f(*orient))
            xform.SetScale(scale)

image

As shown in the picture, I want to change the translate, orient, and scale values in the simulation and apply them to a specific prim.

However, I don’t know how to apply these values in real-time.

It seems that the SimpleFloatModel does not have a method to get the current value. Can you help me figure out how to solve this problem?