jithenderchoudary commited on
Commit
f7ea67c
·
verified ·
1 Parent(s): e038695

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py CHANGED
@@ -9,6 +9,29 @@ import json
9
  import atexit
10
  import glob
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  # Cleanup function to remove temporary files
13
  def cleanup_temp_files():
14
  temp_files = glob.glob("/tmp/*.svg") + glob.glob("/tmp/*.obj") + glob.glob("/tmp/*.stl") + glob.glob("/tmp/*.inp")
 
9
  import atexit
10
  import glob
11
 
12
+ def process_cad_file(file):
13
+ # Check if the file exists and is not empty
14
+ if not os.path.exists(file.name):
15
+ raise ValueError("Uploaded file is missing or does not exist.")
16
+ if os.path.getsize(file.name) == 0:
17
+ raise ValueError("Uploaded file is empty.")
18
+
19
+ # Validate file format
20
+ file_extension = os.path.splitext(file.name)[-1].lower()
21
+ if file_extension not in [".stp", ".step", ".iges", ".igs"]:
22
+ raise ValueError(f"Unsupported file format: {file_extension}")
23
+
24
+ # Process the valid CAD file
25
+ try:
26
+ if file_extension in [".stp", ".step"]:
27
+ return cq.importers.importStep(file.name)
28
+ elif file_extension in [".iges", ".igs"]:
29
+ return cq.importers.importStep(file.name) # Same handler for now
30
+ else:
31
+ raise ValueError("Invalid file type detected during processing.")
32
+ except Exception as e:
33
+ raise RuntimeError(f"Error processing the CAD file: {str(e)}")
34
+
35
  # Cleanup function to remove temporary files
36
  def cleanup_temp_files():
37
  temp_files = glob.glob("/tmp/*.svg") + glob.glob("/tmp/*.obj") + glob.glob("/tmp/*.stl") + glob.glob("/tmp/*.inp")