Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -57,17 +57,40 @@ def execute_script():
|
|
| 57 |
with open(script_file, "w") as f:
|
| 58 |
f.write(apdl_script)
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
# Define ANSYS execution command
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
]
|
| 72 |
|
| 73 |
]
|
|
|
|
| 57 |
with open(script_file, "w") as f:
|
| 58 |
f.write(apdl_script)
|
| 59 |
|
| 60 |
+
def execute_script():
|
| 61 |
+
"""Function to execute the APDL script using ANSYS."""
|
| 62 |
+
global apdl_script
|
| 63 |
+
|
| 64 |
+
# Save the APDL script to a file
|
| 65 |
+
script_file = "script.dat"
|
| 66 |
+
with open(script_file, "w") as f:
|
| 67 |
+
f.write(apdl_script)
|
| 68 |
+
|
| 69 |
# Define ANSYS execution command
|
| 70 |
+
ansys_command = [
|
| 71 |
+
"C:\\Program Files\\ANSYS Inc\\v211\\ansys.exe", # Replace with actual path
|
| 72 |
+
"-b",
|
| 73 |
+
"-i", script_file,
|
| 74 |
+
"-o", "output.log"
|
| 75 |
+
]
|
| 76 |
+
|
| 77 |
+
try:
|
| 78 |
+
# Run the ANSYS command
|
| 79 |
+
subprocess.run(ansys_command, check=True)
|
| 80 |
+
|
| 81 |
+
# Check if 2D and 3D images exist
|
| 82 |
+
if os.path.exists("2D_View.jpg") and os.path.exists("3D_View.jpg"):
|
| 83 |
+
return "APDL script executed successfully. 2D and 3D views generated."
|
| 84 |
+
else:
|
| 85 |
+
return "APDL script executed, but 2D/3D images are missing. Check output.log for details."
|
| 86 |
+
|
| 87 |
+
except subprocess.CalledProcessError as e:
|
| 88 |
+
# Return detailed error message
|
| 89 |
+
return f"Error executing APDL script: {str(e)}. Check output.log for details."
|
| 90 |
+
except FileNotFoundError:
|
| 91 |
+
return "ANSYS executable not found. Verify the path in ansys_command."
|
| 92 |
+
|
| 93 |
+
|
| 94 |
]
|
| 95 |
|
| 96 |
]
|