r/prusa • • 1d ago

Creality K1C Ignoring Speed Control - Follow Up Python Code

1 Upvotes
#!/usr/bin/env python3
"""k1c-tokenizer — reorder trailing F (feedrate) tokens in Klipper G-code.

For each non-comment, non-blank line: if the last token is a frequency /
feedrate setting (Klipper ``F`` parameter, e.g. ``F3000``), move that token
to immediately after the G-code command token. Relative order of other
parameters is preserved.

Creality K1C runs Klipper; "frequency" here means the standard feedrate ``F``
token (mm/min), not a printer-specific vibration/frequency M-code. Lines that
are only comments, blank, or lack a trailing ``F`` are left unchanged.
"""

from __future__ import annotations

import argparse
import re
import shutil
import sys
from pathlib import Path

# Klipper / Marlin-style feedrate parameter: F followed by a number
# (optional sign, integer or decimal). Case-insensitive.
F_TOKEN_RE = re.compile(r"^F[+-]?(?:\d+\.?\d*|\.\d+)$", re.IGNORECASE)

# Command token: G/M/T word, or a Klipper extended command (letters/underscores).
# First whitespace-separated token on a code line is treated as the command.
COMMENT_PREFIXES = (";",)
def is_f_token(token: str) -> bool:
    return bool(F_TOKEN_RE.match(token))

def split_inline_comment(line: str) -> tuple[str, str]:
    """Split a line into code part and trailing `;` comment (if any).

    Semicolons inside quoted strings are not expected in G-code; first `;`
    starts the comment (Klipper convention).
    """
    if ";" not in line:
        return line, ""
    code, comment = line.split(";", 1)
    return code, ";" + comment

def reorder_line(line: str) -> str:
    """Reorder a single G-code line if its last token is an F feedrate.

    Preserves original newline style (caller keeps line endings) and any
    trailing inline comment. Leading/trailing whitespace on the code portion
    is normalized to a single trailing space before an inline comment when
    one is present; otherwise trailing whitespace on the code is dropped.
    Blank and full-line comments are returned unchanged.
    """
    # Preserve exact blank / full-line-comment lines (including whitespace-only).
    stripped = line.strip()
    if not stripped:
        return line
    if stripped.startswith(COMMENT_PREFIXES):
        return line

    code, comment = split_inline_comment(line.rstrip("\r\n"))
    code_stripped = code.strip()
    if not code_stripped:
        return line  # whitespace then comment only — leave alone

    tokens = code_stripped.split()
    if len(tokens) < 2:
        return line

    last = tokens[-1]
    if not is_f_token(last):
        return line

    # Already command + F only — nothing to move.
    if len(tokens) == 2:
        return line

    command, *rest = tokens
    # Drop the trailing F; keep any earlier F tokens in their relative order.
    middle = rest[:-1]
    new_tokens = [command, last, *middle]
    if new_tokens == tokens:
        return line

    new_code = " ".join(new_tokens)
    ending = "\r\n" if line.endswith("\r\n") else ("\n" if line.endswith("\n") else "")

    if comment.strip():
        return f"{new_code} {comment.rstrip()}{ending}"
    return f"{new_code}{ending}"

def process_text(text: str) -> tuple[str, int]:
    """Process full file text. Returns (new_text, number_of_lines_changed)."""
    # Splitlines(keepends=True) handles \n, \r\n, and final line without newline.
    lines = text.splitlines(keepends=True)
    out: list[str] = []
    changed = 0
    for line in lines:
        new_line = reorder_line(line)
        if new_line != line:
            changed += 1
        out.append(new_line)
    return "".join(out), changed

def resolve_input_path(explicit: str | None, tool_dir: Path) -> Path:
    if explicit:
        path = Path(explicit).expanduser()
        if not path.is_file():
            raise SystemExit(f"error: input file not found: {path}")
        return path.resolve()

    candidates = sorted(tool_dir.glob("*.gcode"))
    # Also accept common casing variants on case-sensitive FS
    if not candidates:
        candidates = sorted(
            p for p in tool_dir.iterdir() if p.is_file() and p.suffix.lower() == ".gcode"
        )
        candidates = sorted(set(candidates))

    if not candidates:
        raise SystemExit(
            f"error: no .gcode file beside the tool ({tool_dir}). "
            "Pass a path: k1c-tokenizer.py INPUT.gcode"
        )
    if len(candidates) > 1:
        names = ", ".join(p.name for p in candidates)
        raise SystemExit(
            f"error: multiple .gcode files beside the tool ({names}). "
            "Pass which one: k1c-tokenizer.py INPUT.gcode"
        )
    return candidates[0].resolve()

def build_parser() -> argparse.ArgumentParser:
    p = argparse.ArgumentParser(
        prog="k1c-tokenizer",
        description=(
            "Move a trailing F (feedrate/frequency) token to immediately after "
            "the G-code command on each line. Safe default: write *.reordered.gcode."
        ),
    )
    p.add_argument(
        "input",
        nargs="?",
        default=None,
        help="Path to a .gcode file (default: the only .gcode beside this script)",
    )
    p.add_argument(
        "-o",
        "--output",
        default=None,
        help="Output path (default: INPUT with .reordered.gcode suffix)",
    )
    p.add_argument(
        "--in-place",
        action="store_true",
        help="Overwrite INPUT after writing a .bak backup",
    )
    p.add_argument(
        "-n",
        "--dry-run",
        action="store_true",
        help="Print how many lines would change; write nothing",
    )
    return p

def main(argv: list[str] | None = None) -> int:
    args = build_parser().parse_args(argv)
    tool_dir = Path(__file__).resolve().parent
    src = resolve_input_path(args.input, tool_dir)

    if args.in_place and args.output:
        raise SystemExit("error: use either --in-place or -o/--output, not both")

    text = src.read_text(encoding="utf-8", errors="replace")
    new_text, changed = process_text(text)

    if args.dry_run:
        print(f"{src}: {changed} line(s) would change")
        return 0

    if changed == 0:
        print(f"{src}: no changes needed")
        if not args.in_place and args.output is None:
            # Still produce an identical reordered copy for a predictable artifact,
            # unless user asked for in-place (nothing to do) or custom -o.
            pass

    if args.in_place:
        bak = src.with_suffix(src.suffix + ".bak")
        shutil.copy2(src, bak)
        src.write_text(new_text, encoding="utf-8")
        print(f"{src}: reordered {changed} line(s); backup at {bak}")
        return 0

    if args.output:
        out = Path(args.output).expanduser().resolve()
    else:
        # file.gcode → file.reordered.gcode
        out = src.with_name(src.stem + ".reordered.gcode")

    out.write_text(new_text, encoding="utf-8")
    print(f"{src} → {out}: reordered {changed} line(s)")
    return 0

if __name__ == "__main__":
    sys.exit(main())

r/prusa • • 2d ago

Prusa Core One Wifi issues - adding a Pi connected to ETH

Thumbnail reddit.com
2 Upvotes

r/prusa • • 3d ago

Issue prusa experience to hit rigid support bottlenecks

Thumbnail reddit.com
4 Upvotes

r/prusa • • 4d ago

Prusa XL to XL+ Upgrade – My Guide, Lessons & Print Tests

Post image
9 Upvotes

After spending two full days upgrading my five-toolhead Prusa XL to the XL+, I decided to document the entire experience and share what I learned with the community.

Rather than simply repeating the official assembly instructions, I wanted to focus on the things I would have liked to know before starting the upgrade.

I've put together a detailed guide covering:

  • Compatibility and additional parts you may need
  • Downloadable BOM in PDF and Excel formats
  • Installation issues and practical workarounds
  • Belt tension, XY alignment and calibration
  • Firmware-related issues and troubleshooting
  • VFA, ringing, cooling and multi-color print tests
  • My personal assessment of the upgrade

I've also documented my measurements and calibration results, along with the limitations of my testing. Unfortunately, I didn't print dedicated comparison models before the upgrade, so I'm not making any unsupported claims about improvements in print quality.

You can find the full guide here:

https://investegate.de/prusa-xl-to-xl-plus-upgrade-guide/

It's freely accessible and independently written.

I'm particularly interested in hearing how the upgrade went for other XL owners. If you've encountered any additional issues or have suggestions for improving the guide, I'd appreciate your feedback.


r/prusa • • 4d ago

DHL issues- FCC clearance for boards?

1 Upvotes

I always get a lot of emails and texts from DHL, but this has to be a new record. 24 so far and I don’t have my stuff yet, shipped 7 days ago. I ordered ASA pellets, and for my XL the splitter and sandwich boards. I’ve got an electrical gremlin that help chat and I can’t chase down- a different issue. The issue is that I got messages that I cleared customs, but then I got some messages that made it look like one of the boards is being held up by the FCC. I ‘think’ that things are moving now, we’ll see if they get here tomorrow as DHL is showing.
The other issue is that on Wednesday, I got a TXT that they had tried to deliver it, but that there was no one to sign for it. I was in my front yard all morning and RING camera saw nothing. Contacted DHL, some automation, eventually got to something that responded. They said that the text was in error??? Which it was, but I couldn’t get anything else out of who/what-ever was responding. Wednesday was the original delivery date, and I’ve run into UPS ‘wish-posting’ where they report where it ‘should’ be, not where it actually is. I guess 99%+ of the time that works out. Really disappointed with DHL, which has been pretty solid with Prusa orders in the past, while FedEX has been a few dollars less and a lot more unreliable, until now.
Anyone else having issues with DHL in general or specifically shipping boards with radio functionality? Printed Solid didn’t have the boards in stock, that would have made things more direct.


r/prusa • • 4d ago

OpenPrintTag... unable to save filament consumption

Thumbnail reddit.com
2 Upvotes

r/prusa • • 5d ago

Issue Prusa shipping chaos

5 Upvotes

In case anyone was wondering, the problems with Prusa shipping also extend to their US facility. I ordered a Prusa XL+ in early November with a promise of "shipping by the end of November."

Today is the 30th. I called their office this morning to get an update since I'd heard nothing, and they said that they "experienced a shipping delay" in getting their printers from overseas, and had no ETA of when my order would arrive.

Does anyone know what this means? Am I looking at a 1 month delay? 2 Months?

I timed my work vacation based on the expected shipping date, and am pissed that I won't get to use it.


r/prusa • • 5d ago

Question Could I ask if this sound is normal?

1 Upvotes

When I triggered the "home calibration," it started making the sound heard in the second clip, so I decided to turn the machine off.


r/prusa • • 5d ago

DHL issues- FCC clearance for boards?

1 Upvotes

I always get a lot of emails and texts from DHL, but this has to be a new record. 24 so far and I don’t have my stuff yet, shipped 7 days ago. I ordered ASA pellets, and for my XL the splitter and sandwich boards. I’ve got an electrical gremlin that help chat and I can’t chase down- a different issue. The issue is that I got messages that I cleared customs, but then I got some messages that made it look like one of the boards is being held up by the FCC. I ‘think’ that things are moving now, we’ll see if they get here tomorrow as DHL is showing.
The other issue is that on Wednesday, I got a TXT that they had tried to deliver it, but that there was no one to sign for it. I was in my front yard all morning and RING camera saw nothing. Contacted DHL, some automation, eventually got to something that responded. They said that the text was in error??? Which it was, but I couldn’t get anything else out of who/what-ever was responding. Wednesday was the original delivery date, and I’ve run into UPS ‘wish-posting’ where they report where it ‘should’ be, not where it actually is. I guess 99%+ of the time that works out. Really disappointed with DHL, which has been pretty solid with Prusa orders in the past, while FedEX has been a few dollars less and a lot more unreliable, until now.
Anyone else having issues with DHL in general or specifically shipping boards with radio functionality? Printed Solid didn’t have the boards in stock, that would have made things more direct.


r/prusa • • 5d ago

Issue Unable to resolve CORE One L issues or get support response

1 Upvotes

I’m posting here because I’m currently unable to get a proper response from Prusa support, and emails sent to [email protected] regarding a return have also gone unanswered.

I bought a Prusa CORE One L and have been dealing with several issues almost from the beginning. The main one is extremely slow network file transfers — a file of around 7 MB can take 20–25 minutes to transfer.

This was tested extensively over both Wi-Fi and Ethernet, so it is not simply a wireless signal problem.

During troubleshooting I have already:

  • tested Prusa Connect and PrusaLink;
  • tested Wi-Fi, Ethernet and a phone hotspot;
  • tested multiple USB drives;
  • replaced the Wi-Fi module;
  • replaced the LCD board;
  • replaced the xBuddy board;
  • and followed multiple firmware and troubleshooting steps.

Even after replacing the xBuddy board, the transfer problem is still present.

I also had a recurring Cooling Fan Error. Prusa sent a replacement fan, but replacing it did not solve that issue either.

What has been especially frustrating is how slowly the support process has moved. I have spent a lot of time testing, replacing parts and waiting for escalations or promised follow-ups, yet months later the main problem is still unresolved.

At this point, several major components have already been replaced and I no longer have confidence in the printer or in continuing another troubleshooting cycle.

The printer has very few operating hours, I still have the original packaging, it has been carefully handled, and only one nozzle has been used.

I know I am outside the normal 60-day return period, but a significant amount of the time since purchase has been spent troubleshooting these problems with Prusa and waiting for parts or responses.

Given the circumstances, I would like to discuss an exception and return the printer for a refund rather than continue replacing components indefinitely.

At this point I’m simply trying to reach someone at Prusa who can review the complete case history and actually discuss the return with me.


r/prusa • • 9d ago

Question Fusion360 files for Printables?

Thumbnail reddit.com
1 Upvotes

r/prusa • • 9d ago

Table or something more solid?

Thumbnail reddit.com
1 Upvotes

r/prusa • • 10d ago

MKBHD! Prusa XL spotted.

Post image
3 Upvotes

r/prusa • • 12d ago

Question [Prusa one core + Gen 2] Nozzle Cleaning not Working

Post image
4 Upvotes

r/prusa • • 12d ago

Question Material Warehouse print settings

4 Upvotes

I noticed last week that the prusa slicer has a feature through prusa connect to keep track of the material in your inventory, even going so far as to allow you to note print temps and location you have it stored, which i thought was really cool.

But uh, now i have all that data saved, none of those material presets are saved to my software. Is there a quick way for me to download all the profiles for the filament I have logged in the database?

Or am I going to have to write down what I have then add them all myself through the wizard?


r/prusa • • 13d ago

Where can I get a replacement for this part?

Post image
3 Upvotes

r/prusa • • 14d ago

First XL+ print

Post image
2 Upvotes

r/prusa • • 14d ago

Free shipping isn’t free in America.

Thumbnail reddit.com
0 Upvotes

r/prusa • • 16d ago

Creality K1C Ignoring Speed Control

Post image
2 Upvotes

I've been fighting an issue off an on with the K1C at my workplace that has suddenly rendered itself unsolvable. When entering my speed controls into Prusa Slicer (right) it seems to produce G Code with the opposite format of Creality (left) in that the F-Parameter is on the opposite end of the line. I would expect Creality is smart enough to parse the parameters from the line in any order, but it seems to buffer them in the order they are received. This has the effect that the rapid travel speeds are used in the print moves, and vice versa. I previously resolved this by setting all of the moves to the desired print speed so I could focus on other tasks.

Recently, with no changes to the firmware, it has suddenly started ignoring the speed commands for specifically infill moves, which it is performing at the maximum printer travel speed of 600 mm/s (eyeball guess) rather the commanded 300 mm/s (right code shows 150 as it is a project with combined infill). It prints wicked fast, but with less than half the infill it is supposed to have.

Is there some setting or G Code substitution I can make to resolve this, or will I need to make a script to reorder all the F-commands to the start of the line?


r/prusa • • 17d ago

Powering the Basic Board by connecting the PSU in parallel?

3 Upvotes

So I have a GPIO Hackerboard, an MK4 Enclosure Basic Board, and the White LED strip (from the enclosure add-on).

I want to add additional lighting to the Core One INDX. There are several options, but to power the basic board I need 24v and using the enclosure psu is adding even more bulk to an already bulky printer. Can I just run two power cables and hook them up to the Core One PSU in parallel? I don't think the basic board is going to draw enough current for it to be a problem, but I don't know. Also, ya know, I don't want it to be dangerous.

Thanks for the help.


r/prusa • • 17d ago

Question Prusa Core One INDX Upgrade Gantry squareness randomness

Thumbnail reddit.com
1 Upvotes

r/prusa • • 17d ago

New User Interface Design

Thumbnail gallery
0 Upvotes

r/prusa • • 19d ago

Xtra Tools for the XL

Thumbnail reddit.com
1 Upvotes

r/prusa • • 19d ago

Core One+ vs Core One L+ dilemma

Thumbnail reddit.com
1 Upvotes