File size: 995 Bytes
a78a098
 
 
 
 
 
 
4f8876d
 
a78a098
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os

def generate_gcode(step_file):
    """
    Generates G-Code for CNC machining from a STEP file.
    """
    try:
        # Save the G-Code to the system's temp directory
        gcode_file = os.path.join("/tmp", "generated_gcode.nc")
        gcode_content = """
        G21 ; Set units to millimeters
        G17 ; Select XY plane
        G90 ; Absolute positioning
        G1 F1500 ; Set feed rate

        G0 Z5 ; Raise Z-axis to safe height
        G0 X0 Y0 ; Move to start position
        G1 Z-1 F300 ; Lower Z-axis to cutting depth

        G1 X10 Y0 ; Cut to the first corner
        G1 X10 Y10 ; Cut to the second corner
        G1 X0 Y10 ; Cut to the third corner
        G1 X0 Y0 ; Return to the start position

        G0 Z5 ; Raise Z-axis to safe height
        M30 ; End program
        """
        with open(gcode_file, "w") as f:
            f.write(gcode_content)

        return gcode_file
    except Exception as e:
        return f"Error in G-Code generation: {e}"