Spaces:
Sleeping
Sleeping
| import pyansys | |
| import gradio as gr | |
| # Function to generate die design using ANSYS MAPDL and save in STEP or STL format | |
| def generate_die_ANSYS(length, width, thickness, die_shape, material_type, file_format): | |
| try: | |
| if length <= 0 or width <= 0 or thickness <= 0: | |
| return "Dimensions must be greater than zero." | |
| # Launch ANSYS MAPDL session | |
| mapdl = pyansys.launch_mapdl() | |
| mapdl.clear() # Clear any previous settings | |
| # Preprocessing | |
| mapdl.prep7() | |
| # Die shape logic based on the die shape selected | |
| 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 | |
| elif die_shape == "Progressive": | |
| mapdl.block(0, length, 0, width, 0, thickness) | |
| mapdl.cylinder(0, 0, width / 2, 0, thickness) # Combination of block and cylinder | |
| # Material type logic (could adjust properties based on material type) | |
| if material_type == "Steel": | |
| mapdl.material(1) # Steel material properties | |
| elif material_type == "Aluminum": | |
| mapdl.material(2) # Aluminum material properties | |
| # Define the filename and save based on chosen file format | |
| filename = f"generated_die_{die_shape}_{length}x{width}x{thickness}_{material_type}.{file_format}" | |
| if file_format == "step": | |
| mapdl.save_as(filename) | |
| elif file_format == "stl": | |
| mapdl.save_as_stl(filename) | |
| mapdl.exit() # Close the session | |
| # Return success message with download link | |
| 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 | |
| def progressive_die_interface(length, width, thickness, die_shape, material_type, file_format): | |
| return generate_die_ANSYS(length, width, thickness, die_shape, material_type, file_format) | |
| # Create the Gradio Interface | |
| with gr.Blocks() as app: | |
| gr.Markdown("## Sree Ramana Press Tools - Die Design Generator") | |
| gr.Markdown("Enter the dimensions and material for the die design:") | |
| with gr.Tabs(): | |
| # Tab for Progressive Die Design | |
| with gr.Tab("Progressive Die Design"): | |
| gr.Markdown("### Enter Dimensions and Material for Die Design") | |
| 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", "Progressive"], value="Rectangle") | |
| material_type = gr.Dropdown(label="Material Type", choices=["Steel", "Aluminum"], value="Steel") | |
| file_format = gr.Dropdown(label="File Format", choices=["step", "stl"], value="step") | |
| die_output = gr.Textbox(label="Output") | |
| die_button = gr.Button("Generate Die") | |
| die_button.click(progressive_die_interface, inputs=[length, width, thickness, die_shape, material_type, file_format], outputs=die_output) | |
| # Launch the app | |
| app.launch() | |