TAM‑CNC Interpolation G-Code Generator

Interpolation G-code Generator

Interpolation Diagram

Enter your parameters below to generate G-code for hole interpolation or thread milling.

import js from pyscript import display def generate_interpolation_gcode(event): try: # Get values from HTML input elements tool_no = js.document.getElementById("int-tool-no").value tool_dia = float(js.document.getElementById("int-tool-dia").value) tool_rad = tool_dia / 2 wrk_ofset = js.document.getElementById("int-work-offset").value spdle_rpm = js.document.getElementById("int-spindle-rpm").value x_pos = float(js.document.getElementById("int-x-position").value) y_pos = float(js.document.getElementById("int-y-position").value) z_rapid = float(js.document.getElementById("int-z-rapid").value) z_start = float(js.document.getElementById("int-z-start").value) z_cut = float(js.document.getElementById("int-z-cut").value) nosteps = int(js.document.getElementById("int-nosteps").value) diam = float(js.document.getElementById("int-diameter").value) rad = diam / 2 feedrate = float(js.document.getElementById("int-feed-rate").value) # --- G-code generation logic based on provided Python script --- gcode_lines = [] gcode_lines.append("%") # Start of program gcode_lines.append("M97 P8000") gcode_lines.append("G21 (G21 for millimeters, G20 for inches)") gcode_lines.append("M05") gcode_lines.append(f"T{tool_no} M06") gcode_lines.append(f"M03 S{spdle_rpm}") gcode_lines.append(f"G{wrk_ofset}") gcode_lines.append("G40") gcode_lines.append("G98 G17") gcode_lines.append(f"G00 X{x_pos:.2f} Y{y_pos:.2f} (All XY movements in sub-program are)") gcode_lines.append(f"G{wrk_ofset} G00 Z{z_rapid} G43 H{tool_no} M08") gcode_lines.append(f"G01 Z{z_start} F{feedrate/2:.2f}") gcode_lines.append("M97 P401") gcode_lines.append("(For multiple holes add more XY positions and re-run Sub-program)") gcode_lines.append(f"G00 Z{z_rapid + 20} M09") gcode_lines.append("M05") gcode_lines.append("M97 P8000") gcode_lines.append("M30") gcode_lines.append("\nN401") gcode_lines.append(f"G90 G01 Z{z_start} F{feedrate/2:.2f}") gcode_lines.append(f"G91 G01 X{rad - tool_rad:.2f} F{feedrate/2:.2f}") gcode_lines.append(f"G91 G02 Z-{z_cut:.2f} I-{rad - tool_rad:.2f} F{feedrate:.2f} L{nosteps}") gcode_lines.append(f"(For a bottom finish hole, use this line -- G02 I-{rad - tool_rad:.2f})") gcode_lines.append(f"G91 G01 X-{rad - tool_rad:.2f} F{feedrate/2:.2f}") gcode_lines.append(f"G90 G01 Z{z_start}") gcode_lines.append(f"G00 Z{z_rapid}") gcode_lines.append("M99") gcode_lines.append("\nN8000") gcode_lines.append("G00 G90 M09") gcode_lines.append("G53 G00 G40 Z0") gcode_lines.append("G53 G00 G40 X0 Y0") gcode_lines.append("M01") gcode_lines.append("M99") gcode_lines.append("%") # End of program # Display the generated G-code output_element = js.document.querySelector("#int-gcode-output pre code") output_element.innerText = "\n".join(gcode_lines) except Exception as e: output_element = js.document.querySelector("#int-gcode-output pre code") output_element.innerText = f"Error generating G-code: {str(e)}\nPlease check your input values." # Placeholder for the function definition itself, as py-click handles the event. pass












Generated G-code:

Disclaimer: All CNC toolpaths and G‑code generated or displayed by this tool must be reviewed and verified by the machine operator before use. TAM‑CNC and its developers accept no liability for machine damage, material loss, or personal injury resulting from improper use.