jithenderchoudary commited on
Commit
f22f137
·
verified ·
1 Parent(s): 2754387

Create design.py

Browse files
Files changed (1) hide show
  1. design.py +42 -0
design.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cadquery as cq
2
+ import os
3
+ import pyvista as pv
4
+
5
+ def generate_die(length, width, thickness):
6
+ try:
7
+ output_dir = "outputs"
8
+ os.makedirs(output_dir, exist_ok=True)
9
+
10
+ plate = cq.Workplane("XY").box(length, width, thickness)
11
+ punch = cq.Workplane("XY").rect(10, 10).extrude(5).translate((length / 4, width / 4, thickness / 2))
12
+ die = plate.cut(punch)
13
+
14
+ filename = os.path.join(output_dir, "progressive_die.step")
15
+ cq.exporters.export(die, filename)
16
+
17
+ return filename
18
+ except Exception as e:
19
+ return f"Error generating die: {str(e)}"
20
+
21
+ def visualize_die(length, width, thickness):
22
+ try:
23
+ output_dir = "outputs"
24
+ os.makedirs(output_dir, exist_ok=True)
25
+
26
+ plate = cq.Workplane("XY").box(length, width, thickness)
27
+ punch = cq.Workplane("XY").rect(10, 10).extrude(5).translate((length / 4, width / 4, thickness / 2))
28
+ die = plate.cut(punch)
29
+
30
+ stl_file = os.path.join(output_dir, "progressive_die.stl")
31
+ cq.exporters.exportShape(die.val(), "STL", stl_file)
32
+
33
+ pv.global_theme.off_screen = True
34
+ mesh = pv.read(stl_file)
35
+ plotter = pv.Plotter(off_screen=True)
36
+ plotter.add_mesh(mesh, color="blue")
37
+ screenshot = os.path.join(output_dir, "progressive_die_visualization.png")
38
+ plotter.screenshot(screenshot)
39
+
40
+ return screenshot
41
+ except Exception as e:
42
+ return f"Error visualizing die: {str(e)}"