File size: 2,357 Bytes
73f59c6
 
 
71602b2
 
73f59c6
71602b2
 
73f59c6
71602b2
 
73f59c6
 
 
 
 
 
 
71602b2
73f59c6
71602b2
73f59c6
 
71602b2
 
 
73f59c6
71602b2
 
 
73f59c6
71602b2
73f59c6
71602b2
 
 
73f59c6
 
 
71602b2
 
 
 
 
 
 
 
 
 
 
 
 
73f59c6
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from ansys.mapdl.core import launch_mapdl
import gradio as gr

# Function to generate die design using ANSYS MAPDL
def generate_die_ANSYS(length, width, thickness, die_shape):
    try:
        if length <= 0 or width <= 0 or thickness <= 0:
            return "Dimensions must be greater than zero."

        # Launch ANSYS MAPDL session (without interactive argument)
        mapdl = launch_mapdl()  # Start MAPDL session
        mapdl.clear()  # Clear any previous settings

        # Preprocessing
        mapdl.prep7()

        # Die shape logic
        if die_shape == "Rectangle":
            mapdl.block(0, length, 0, width, 0, thickness)  # Create a rectangular block
        elif die_shape == "Circle":
            mapdl.cylind(0, 0, width / 2, 0, thickness)  # Create a cylindrical block

        # Save the geometry as a STEP file
        filename = f"generated_die_{die_shape}_{length}x{width}x{thickness}.step"
        mapdl.save_as(filename)  # Save the design as STEP file
        mapdl.exit()  # Exit the MAPDL session

        # Return success message with the file path
        return f"Die design saved successfully as {filename}. You can download the file."
    
    except Exception as e:
        return f"Error generating die design: {str(e)}"

# Gradio interface functions for Progressive Die Design
def progressive_die_interface(length, width, thickness, die_shape):
    return generate_die_ANSYS(length, width, thickness, die_shape)

# Create the Gradio Interface
with gr.Blocks() as app:
    gr.Markdown("## Progressive Die Design Tool with ANSYS")
    gr.Markdown("Select the dimensions and shape for the progressive die below:")

    # Tab for Progressive Die Design
    with gr.Tab("Progressive Die Design"):
        gr.Markdown("### Enter Dimensions and Shape for Progressive Die")
        length = gr.Number(label="Length (mm)", value=100)
        width = gr.Number(label="Width (mm)", value=50)
        thickness = gr.Number(label="Thickness (mm)", value=10)
        die_shape = gr.Dropdown(label="Die Shape", choices=["Rectangle", "Circle"], value="Rectangle")
        die_output = gr.Textbox(label="Output", interactive=False)
        die_button = gr.Button("Generate Die")
        die_button.click(progressive_die_interface, inputs=[length, width, thickness, die_shape], outputs=die_output)

# Launch the app
app.launch()