karthikmn commited on
Commit
b625db9
·
verified ·
1 Parent(s): d7d8c55

Create Gecoder/generate_gcode.py

Browse files
Files changed (1) hide show
  1. Gecoder/generate_gcode.py +39 -0
Gecoder/generate_gcode.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ def generate_gcode(cad_file):
4
+ """
5
+ Generates a simple G-Code file for a square cut.
6
+ """
7
+ try:
8
+ # Ensure the output directory exists
9
+ output_dir = "/mnt/data/"
10
+ os.makedirs(output_dir, exist_ok=True)
11
+
12
+ # Define the G-Code content
13
+ gcode_content = """
14
+ G21 ; Set units to millimeters
15
+ G17 ; Select XY plane
16
+ G90 ; Absolute positioning
17
+ G1 F1500 ; Set feed rate
18
+
19
+ G0 Z5 ; Raise Z-axis to safe height
20
+ G0 X0 Y0 ; Move to start position
21
+ G1 Z-1 F300 ; Lower Z-axis to cutting depth
22
+
23
+ G1 X10 Y0 ; Cut to the first corner
24
+ G1 X10 Y10 ; Cut to the second corner
25
+ G1 X0 Y10 ; Cut to the third corner
26
+ G1 X0 Y0 ; Return to the start position
27
+
28
+ G0 Z5 ; Raise Z-axis to safe height
29
+ M30 ; End program
30
+ """
31
+
32
+ # Save the G-Code to a file
33
+ gcode_file = os.path.join(output_dir, "generated_gcode.nc")
34
+ with open(gcode_file, "w") as f:
35
+ f.write(gcode_content)
36
+
37
+ return gcode_file
38
+ except Exception as e:
39
+ return f"Error in G-Code generation: {e}"