Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from ansys.mapdl.core import launch_mapdl
|
| 3 |
+
import win32com.client
|
| 4 |
+
|
| 5 |
+
def generate_cad_and_simulate(part_name, length, width, height, material_property):
|
| 6 |
+
# Step 1: Create Geometry in SolidWorks (CAD Automation)
|
| 7 |
+
try:
|
| 8 |
+
swApp = win32com.client.Dispatch("SldWorks.Application")
|
| 9 |
+
model = swApp.NewPart()
|
| 10 |
+
model.SketchManager.CreateRectangle(0, 0, 0, length / 1000, width / 1000) # Rectangle in mm
|
| 11 |
+
model.FeatureManager.FeatureExtrusion2(True, False, False, 0, 0, height / 1000, 0, False, False, False, False, 0, 0, False, False, False, False)
|
| 12 |
+
cad_path = f"{part_name}.STEP"
|
| 13 |
+
model.Extension.SaveAs(cad_path)
|
| 14 |
+
except Exception as e:
|
| 15 |
+
return f"Error in SolidWorks CAD generation: {e}"
|
| 16 |
+
|
| 17 |
+
# Step 2: Simulate in ANSYS
|
| 18 |
+
try:
|
| 19 |
+
mapdl = launch_mapdl()
|
| 20 |
+
mapdl.prep7()
|
| 21 |
+
mapdl.et(1, "SOLID186")
|
| 22 |
+
mapdl.mp("EX", 1, material_property) # Elastic modulus
|
| 23 |
+
mapdl.input(cad_path)
|
| 24 |
+
mapdl.vmesh("ALL")
|
| 25 |
+
mapdl.solve()
|
| 26 |
+
displacement = mapdl.post_processing.nodal_displacement()
|
| 27 |
+
mapdl.exit()
|
| 28 |
+
except Exception as e:
|
| 29 |
+
return f"Error in ANSYS simulation: {e}"
|
| 30 |
+
|
| 31 |
+
return f"Simulation completed! Displacement results: {displacement}"
|
| 32 |
+
|
| 33 |
+
# Gradio Interface
|
| 34 |
+
iface = gr.Interface(
|
| 35 |
+
fn=generate_cad_and_simulate,
|
| 36 |
+
inputs=[
|
| 37 |
+
gr.Textbox(label="Part Name", placeholder="Enter the part name"),
|
| 38 |
+
gr.Number(label="Length (mm)"),
|
| 39 |
+
gr.Number(label="Width (mm)"),
|
| 40 |
+
gr.Number(label="Height (mm)"),
|
| 41 |
+
gr.Number(label="Material Elastic Modulus (Pa)"),
|
| 42 |
+
],
|
| 43 |
+
outputs="text",
|
| 44 |
+
title="CAD-ANSYS Automation",
|
| 45 |
+
description="Generate CAD models and perform ANSYS simulations automatically!"
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
iface.launch()
|