Can we launch workbench through webapp using PyWB module.?

Options
Naveen Kumar Begari
Naveen Kumar Begari Member Posts: 104
10 Comments 5 Likes First Answer First Anniversary
**

A simple code with webapp, when we click a button, workbench should launch, but here i get an error. Could anyone try this code and confirm.?

import dash
from dash import html, Output, Input
from ansys.workbench.core import launch_workbench
from ansys.mechanical.core import connect_to_mechanical , launch_mechanical
import dash_bootstrap_components as dbc

app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])

app.layout = dbc.Container([
    html.H3("Launch ANSYS Workbench"),
    dbc.Button("Launch Workbench", id="launch-btn", color="primary", className="mt-2"),
    html.Div(id="status", className="mt-3")
])


@app.callback(
    Output("status", "children"),
    Input("launch-btn", "n_clicks"),
    prevent_initial_call=True
)
def run_workbench(n):
    try:
        wb = launch_workbench()
        # m = launch_mechanical()
        return "Workbench launched successfully."
    except Exception as e:
        return f"Failed to launch Workbench: {str(e)}"


if __name__ == "__main__":
    app.run(debug=True)

Answers

  • James Derrick
    James Derrick Administrator, Employee Posts: 379
    Ancient Membership 100 Comments 100 Likes 25 Answers
    admin

    Hi @Naveen Kumar Begari I've had a go at this and I get the same error as you, although it looks like this might be a Dash/Flask issue rather than a PyWorkbench one as it seems something is going wrong in there according to the traceback. I've tried to find a solution but been unable.

  • James Derrick
    James Derrick Administrator, Employee Posts: 379
    Ancient Membership 100 Comments 100 Likes 25 Answers
    admin

    Would someone in the @Structures-Scripting-Team have a better time with this?