Update geometry with the action button

Hello everyone,

I am relatively new to Viktor. I’m developing an app where the geometry should be updated upon the user clicking an action button. The function triggered by the action button initially performs a computation to determine certain parameters, which are then utilized to update the geometry. However, when I invoke the geometry visualization function (decorated with GeometryView) within the action button function (after computing the necessary parameters), I encounter “no attribute available” errors. Is there a solution for this in Viktor, or is this implementation not feasible? Thanks in advance.

Hi there, and welcome to the community forum, thanks for posting!!

Just so I get a clear idea of what you’re trying to do: am I correct in assuming that you want the user to be able to change some parameters without the geometry changing, and then, once the user is happy with their parameter configuration, let them hit the ActionButton after which the geometry gets refreshed?

If that’s the case, I wonder why using the Update button on the bottom right of a “Slow view” is not a viable alternative to the ActionButton?

Hello Daniel,

Thank you very much for the reply. You are almost right about the idea but I would like to add a few more details. In the app, the user gives the input (yes the geometry should not change while the user is giving the input) and clicks on the ActionButton which is when a function runs a computation and returns some parameters. These parameters will then be used to generate/update the geometry. So I wanted to write the app in such as way that as soon as the ActionButton is clicked, the computation should be run and the updated geometry has to be displayed. I tried it with the Slow View approach but the way the update option is shown in the geometry view is not natural for the user to click on it. I want more like a single-click option to run the computation and render the updated geometry immediately after that. Is there a way to update the geometry view through some function that can be linked to the ActionButton or do the same thing through some sort of maybe modified ActionButton? I hope this gives more context to the question. Thanks in advance.

Hi Kubair,

Excuse me if I still do not understand correctly, but wouldn’t your problem be fixed by structuring your app thusly?

class Controller(ViktorController):
    label = "My Controller"
    parametrization = Parametrization

    @GeometryView("Geometry", duration_guess=5)
    def render_geometry(self, params: Munch, **kwargs: dict) -> GeometryResult:
        """update geometry"""
        calculation_result = self.run_calculation(params)
        
        geom = geometry.based_on_calculation(calculation_result)
        
        return GeometryResult(geom)

    def run_calculation(self, params: Munch, **kwargs: dict):
        """some calculation"""
        b = 2 * params.a
        calculation_result = run_some_calculation

        return calculation_result

Or is your main problem that the update button in this case is on the bottom right of the view instead of in the parametrization?

Hi Daniel,

Thanks for the reply. The main issue with our idea is that the input field in our interface is a long text-type input (TextAreaField). So the user can give a very long input. I think your implementation above would run the run_calculation method whenever the user is typing the input and takes a small break in between (even when he is not fully done with writing the input) right? So we wanted to add an ActionButton so that the user clicks on it when he/she is done with the full input. Also, we can’t run the computation every time when they stop because it is an expensive computation. I hope that gives a bit more clarity.

No in the setup I presented the view is a slow one (duration_guess=5). So it will only be triggered when the user clicks the Update button, not when the parametrization is triggered by the user start/stopping the typing.

Ok, that’s great. But is there a way to link the functionality of the Update button to an ActionButton or some other option that can be triggered by the user in the main UI?