Jump to content

Using GCode Documentation Post Processing Script with Ender Thumbnail Generator


PartySausage
Go to solution Solved by PartySausage,

Recommended Posts

Posted · Using GCode Documentation Post Processing Script with Ender Thumbnail Generator

I was wanting to use the GCode Documentation Post Processing Script to add the formatted print settings to the GCode file for future reference, however I can't find a way to use it in conjunction with my thumbnail generator script for the print preview on my Ender 3 S1 Pro screen. 

The Ender 3 S1 Pro requires that the thumbnail jpg code is the first item in the GCode file or it won't display on the printer so I can't configure the position for the GCode Documentation script to be at the top of the file (Line 0).

Due to the nature of the generated thumbnail code, the number of lines it creates depends on the size of the print so I can't configure the position for the GCode Documentation script to be at a specific line so it would be after the thumbnail code.

Is there anyway I can tweak the GCode Documentation python script with to position to info either before of after a specific bit of unique text that appears somewhere near the top of the GCode file as opposed to a specific line number eg before ;FLAVOR:Marlin  or after ;jpg end

 

; UUAFFFFABRRRQAUUUUAFFFFABRRRQB//2Q==
; jpg end
;

;FLAVOR:Marlin
;TIME:11661
;Filament used: 8.03948m

  • Link to post
    Share on other sites

    Posted · Using GCode Documentation Post Processing Script with Ender Thumbnail Generator

    I can't even get that script to work, but I might be able to help anyway. It says it's been processed using the script but I don't see any documentation.

     

    First I had to track the damn thing down - in my case it the only Gcode Documentation script was part of a plugin, in my case it was installed in %APPDATA%\cura\5.6\plugins\HTMLCuraSettings\HTMLCuraSettings\resources\scripts - if yours came from a different source then these instructions might not apply at all. Also, please tell me where you got a thumbnail generator for Ender machines, I haven't managed to find one.

     

    Anyways, open GCodeDocumentation.py in a text editor and go right down to the bottom. Line 639, at least in my instance:

    layer = data[0]

    Try changing that to:

    layer = data[1]

    That will make it appear at the top of the next layer, I can't remember whether all the preamble is considered its own layer or not but just search the file or scroll down (but only a layer or two) to see if you can find it.

  • Link to post
    Share on other sites

    Posted · Using GCode Documentation Post Processing Script with Ender Thumbnail Generator

    Thanks @Slashee_the_Cow for taking a look at this.

    I was originally trying to use it via the preinstalled script located in the %APPDATA%\cura\5.6\plugins\HTMLCuraSettings\HTMLCuraSettings\resources\scripts folder but it seemed to be working sporadically & output didn't always change when I made a settings change so I moved the script from there to %APPDATA%\cura\5.6\scripts folder & it seems to work much better from there.

    The file also resides in %APPDATA%\cura\5.6\plugins\CalibrationShapes\CalibrationShapes\resources\scripts

     

    I tried changing the line you suggested in the script. The GCode Documentation does get added in a better location however the thumbnail code is either being removed or isn't being generated. I also tried changing the order where the GCode Documentation script is in the Post Processor list in relation to the thumbnail scripts, however the results were the same. I've attached copies of the same print GCodes with the two settings for comparison

    layer = data[0].gcode layer = data[1].gcode

  • Link to post
    Share on other sites

    Posted (edited) · Using GCode Documentation Post Processing Script with Ender Thumbnail Generator

    Seems like the version from CalibrationShapes (didn't have it installed) is newer and actually works. It would still be nice to know where you got the script for the Ender-3 thumbnails because a) I can't find it, b) it would really help to test them together and c) I have an Ender-3 V3 SE.

     

    That being said, with it actually working I figured out it was time to play hardball, even if I don't have the Ender-3 thumbnail post to work with (hint hint). This will make it ignore looking for at the top for spot entirely and just add itself at the end of the file. Change the block starting with the layer index to this - I've commented out everything it does automatically to find a place and just made it tack itself on at the end of the fie.

            # Ajoute en début de GCode les infos
            """layer = data[0]
            layer_index = data.index(layer)
            lines = layer.split("\n")
            # Ajoute en deuxieme ligne
            lines.insert( pos_insert, replace_string)
            final_lines = "\n".join(lines)
            data[layer_index] = final_lines"""
            data.append(replace_string)

    That may or may not be hard to copy+paste because of the indenting (which is important in Python). Just put triple double quotes """ at the start of the line layer = data[0] and after the line data[layer_index] = final_lines and then on a new line at the end put data.append(replace_string)

    Edited by Slashee_the_Cow
  • Link to post
    Share on other sites

    Posted · Using GCode Documentation Post Processing Script with Ender Thumbnail Generator
    1 hour ago, Slashee_the_Cow said:

    Seems like the version from CalibrationShapes (didn't have it installed) is newer and actually works. It would still be nice to know where you got the script for the Ender-3 thumbnails because a) I can't find it, b) it would really help to test them together and c) I have an Ender-3 V3 SE.

     

    That being said, with it actually working I figured out it was time to play hardball, even if I don't have the Ender-3 thumbnail post to work with (hint hint). This will make it ignore looking for at the top for spot entirely and just add itself at the end of the file. Change the block starting with the layer index to this - I've commented out everything it does automatically to find a place and just made it tack itself on at the end of the fie.

            # Ajoute en début de GCode les infos
            """layer = data[0]
            layer_index = data.index(layer)
            lines = layer.split("\n")
            # Ajoute en deuxieme ligne
            lines.insert( pos_insert, replace_string)
            final_lines = "\n".join(lines)
            data[layer_index] = final_lines"""
            data.append(replace_string)

    That may or may not be hard to copy+paste because of the indenting (which is important in Python). Just put triple double quotes """ at the start of the line layer = data[0] and after the line data[layer_index] = final_lines and then on a new line at the end put data.append(replace_string)

    Thanks again. I'll copy the code into my script when I get home later.

    The ender thumbnail generator was a third party script I found that was originally created for the Neo2, and I tweaked for the S1 Pro based on the thumbnail generated by the creality slicer, which worked. I discussed it in the post linked below when another user was having trouble getting the thumbnail to display on their ender. The script is attached to the post https://community.ultimaker.com/topic/44667-no-thumbnail-on-creality-3-vs2/?do=findComment&comment=328530887

  • Link to post
    Share on other sites

    • Solution
    Posted · Using GCode Documentation Post Processing Script with Ender Thumbnail Generator

    I hadn't realised that the version from CalibrationShapes was newer than the HTMLCuraSettings version so I copied the newer version over & modified that version in line with your suggestions. You're not wrong when you mentioned the script files are very picky about the layout formatting🤬

     

    Your 2nd suggestion works with that version, appending the info to the end of the file with the added benefit 

     

    With that version I was also able to get your original suggestion of using layer = data[1] to work, which positioned the documented settings after the section with the ;FLAVOR: Marlin, however in this location it was causing some problems with display of the layer info in the Mintion App when printing via my BeagleCam. As I really wanted to have the documented settings near the top of the GCode file I thought I'd dig a bit deeper into the cause.

     

    I worked out that offending line was :

     

     #   layer_height
      replace_string = replace_string + self.GetDataExtruder(extruder_id,"layer_height")

     

    which documented to the following in the GCode file:

    ; Layer Height                                           : 0.20 mm

     

    I tested by removing this line & the layer info was displayed correctly. I presumed the BeagleCam must have been looking for a line with ; layer with the first occurrence in the GCode file usually being ;LAYER_COUNT:xx and this being declared further down the GCode file so with the documented setting line not containing the total layers the BeagleCam wasn't identifying the total layers correctly.

     

    I think I've found a way to over come this with a couple of script tweaks....

     

    The first was to append each documented setting with a '>', which needed to be done in two places to give for example  ;> Layer Height                                           : 0.20 mm

     

        def SetSpace(self,key,dec=0):
            dec_line = " " * int(dec)
            string_val = dec_line + str(key)
            new_line = "\n;> " + '{:55}'.format(string_val) + ": "
            return new_line

        def SetSect(self,key):
            new_line = "\n;>  + '{:-^78}'.format(str(key))
            return new_line

    # Get de value and Label and format the text

     

    However just doing this the total layers displayed in the BeagleCam app was the actual total layers + 1 so I made another tweak, which extracted the  ;LAYER_COUNT:xx line from the GCode file & appended it to the GCode before the documented settings, which seems to work a treat.

     

            layer_count_string = ""

     

            for layer in data:
                layer_index = data.index(layer)
                lines = layer.split("\n")
                for line in lines:
                    if line.startswith(";LAYER_COUNT:"):
                        layer_count_string = line

     

            replace_string = "\n;"
            replace_string = replace_string + "\n" + layer_count_string
            replace_string = replace_string + "\n;"

     

    I've attached my modified file & a sample GCode file if you want to have a look, cheers for the pointers

     

    GCodeDocumentation.zip layer = data[1] TEST.gcode

  • Link to post
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
    • Our picks

      • UltiMaker Cura 5.8 Stable released 🎉
        In the Cura 5.8 stable release, everyone can now tune their Z seams to look better than ever. Method series users get access to new material profiles, and the base Method model now has a printer profile, meaning the whole Method series is now supported in Cura!
        • 5 replies
      • Introducing the UltiMaker Factor 4
        We are happy to announce the next evolution in the UltiMaker 3D printer lineup: the UltiMaker Factor 4 industrial-grade 3D printer, designed to take manufacturing to new levels of efficiency and reliability. Factor 4 is an end-to-end 3D printing solution for light industrial applications
          • Thanks
          • Like
        • 3 replies
    ×
    ×
    • Create New...