Altering G-Code

That use case make sense.

If you upload the .gcode.3mf file for the print I can add the pause where you specify. This isn’t a long term solution but it would get you going on this print.

That’s extremely generous of you!

But I did just happen to think I can run Windows 10 on my Mac Using Parallels. If I installed bamboo studio for Windows on there then maybe I could install 7zip and be able to do it the way you instructed above. Do you think that would work?

Sort of like showing you how to fish rather than simply giving me one. :wink:

That may work but I would really think there should be a native app for Mac’s that can do this.

Yup, I’d much rather teach someone to do it for themselves but I wasn’t sure if this was single use case and would save you a bunch of time.

If you’re using mac and feeling spicy, you can do all the same things with tar on command line. I’m rusty, but I bet claude could give you a 1liner that gets you the gcode file out of the 3mf, lets you edit it, and a 1liner that puts it back. 3mf is just a zip and a zip is just a tar and a tar is one of the oldest file formats out there, a vast garden of mature tools to use

Actually, I’m setting up to print many many of these to sell online. I’m a piano teacher and have developed this system for teaching students how to read sheet music from scratch. These key identifiers are color-coded with a bunch of classical music I’ve color-coded to match the notes on a keyboard.

So it would probably be the sort of thing that would be best I learned how to do for long-term availability. :wink:

That would be incredible and much appreciated if you could point me in the right direction where I could develop this skill! I have used the command line in the macOS from time to time. But really I’m just more familiar with it rather than savvy with it. :smiling_face_with_sunglasses:

By coincidence I was watching a video yesterday where they explained how to setup python environments in a Mac - which might be of interest.

I haven’t done it for quite a while - this bit of python code opens up a 3mf file - and modifies a gcode file within it - in case it is of any use.

#!/usr/bin/python3




import sys
import re
import os

import io

import pprint
import json


from zipfile import ZipFile

import xml.etree.ElementTree as ET

import logging
logging.basicConfig(filename='/var/log/dwpython/dw3mf.log', encoding='utf-8', level=logging.DEBUG)

try:

            
    if len(sys.argv) > 1:
        sourceFile=sys.argv[1]
    else:
        print("no argv")
        sys.exit()


    if not sourceFile.endswith("gcode.3mf"):
        print("Error Not GCODE File")
        exit(0)

    count = 0
    extrude = 0.0

    with ZipFile(sourceFile, "r") as f3mf:

        outFile = sourceFile.replace("gcode.3mf","noprime.gcode.3mf")
        with ZipFile(outFile, "w") as f3mf_o:
                for name in f3mf.namelist():
                    buffer = f3mf.read(name)

                    if name.endswith(".gcode"):     
                        print(name)

                        primeX1 = 999
                        primeX2 = -1
                        primeY1 = 999
                        primeY2 = -1
                        x = -1.0
                        y = -1.0
                        bPrimeCaptured = False
                        bCapture = False


                        with io.TextIOWrapper(f3mf.open(name), encoding="utf-8") as f:
                            lines = f.readlines()

                            bComment = False

                            for lIndex in range(len(lines)):
                                oline = lines[lIndex]

                                if oline.startswith("; FEATURE: Prime tower") and not bPrimeCaptured:
                                    print("Prime Start")
                                    bCapture  = True
                                    bPrimeCaptured = True
                                    

                                if bCapture and oline.startswith("; WIPE_END"):
                                    print("wipe end")
                                    bCapture = False
                                    
                                    print("Prime Captured")
                                    print("primeX1",round(primeX1,2))
                                    print("primeX2",round(primeX2,2))
                                    print("primeY1",round(primeY1,2))
                                    print("primeY2",round(primeY2,2))

                                if oline.startswith("G0") or oline.startswith("G1"):
                                    for p in oline.split(";")[0].split(" "):
                                        if p.startswith("X"):
                                            x = float((p[1:].strip()))
                                        if p.startswith("Y"):
                                            y = float(str.strip(p[1:]))

                                if bCapture and x != -1 and x < primeX1:
                                    primeX1 = x
                                if bCapture and x != -1 and x > primeX2:
                                    primeX2 = x

                                if bCapture and y != -1 and y < primeY1:
                                    primeY1 = y
                                if bCapture and y != -1 and y > primeY2:
                                    primeY2 = y


                            for lIndex in range(len(lines)):
                                oline = lines[lIndex]

                                if oline.startswith("G0") or oline.startswith("G1"):
                                    e = 0.0
                                    for p in oline.split(";")[0].split(" "):
                                        if p.startswith("E"):
                                            e = float(str.strip(p[1:]))
                                        if p.startswith("X"):
                                            x = float(str.strip(p[1:]))
                                        if p.startswith("Y"):
                                            y = float(str.strip(p[1:]))

                                    if x >= primeX1 and x <= primeX2 and y >= primeY1 and y <= primeY2:
                                        lines[lIndex] = ";" + oline
                                        count += 1
                                        extrude += e

                                
                            buffer = "".join(lines)


                    f3mf_o.writestr(name,buffer)  
    print(count,"G0 and G1 commands commented out")
    print(round(extrude/1000,2),"M prime saved")

except AssertionError as error:
    logging.error(error)
    logging.error('The linux_interaction() function was not executed')
                        
           




Hello all. I too am looking to edit my gcode. I am on windows, and I got 7zip earlier tonight trying to follow this conversation.
What I have on my other screen is a python script that updates the purge volumes by a selected amount for all purges in a gcode file. What I want to do is get around the 900 limit in bambu studio, because black to white needs more like 1200. The script is written for 20% right now.

As I type this I realize the way to do this is unzip as above, run the script on the file, then edit inside the archive using 7zip as shown and doing a simple copy paste of the entire contents. Its going to make the machine spirit unhappy but that’s why I fed it so much ram when I built it. Thank you to everyone here for the secret!

When I do gcode editing in python - I personally also get python to do the unzipping and zipping too - as per my 1st May post example.

Also I would be careful about simply updating of purge lengths by multiplying values - as would might find you get jam ups in the purge shoot - you might need to add extra loops of gcode commands to release the purge in batches