Announcement

Collapse
No announcement yet.

Would Like Help With Using Start Code Variables

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Would Like Help With Using Start Code Variables

    Since starting work on my new IDEX printer, I have had to deal with some, admittedly minor, issues with nozzle & bed heating, primarily with getting commands into the gcode file that will cause the nozzle & bed to heat the way I want.

    Of course, I thought about how I could use the Start Code feature of Cura to my advantage. Then, being a very long time programmer, my mind naturally turned to how I might access the variables I just knew had to be used to store values that are set in the Print Settings window. What if I could include variables in the Start Code that Cura would fill in during the slicing process? I searched the Internet & I did find articles that strongly suggest I should indeed be able to do what I hoped I could. Unfortunately, I seem to be doing something wrong, cause it's not working. By that, I mean the gcode produced by Cura does not include command lines that are filled with resolved variables. Instead, Cura simply copies the commands I placed in the Start Code verbatim to the gcode file.

    I found this article: https://cnc.qbytesworld.com/3d-print...es-3d-printer/ which basically told me I should be able to do exactly what I wanted.

    I also found a forum post that told me I could reference a file called fdmprinter.def.json. I searched for that file in the folder on my computer where Cura was installed, and found it. There are many references in the file to variables that Cura uses for user configurable parameters.

    So, my obvious question is, can anyone save me some time & point me in the right direction?




  • #2
    Unfortunately, the name "gcode" promises more than it delivers. 3D printers are profoundly stupid and only understand simple commands. Most run on processors with a fraction of the power of even low-power desktops. Any smarts are in the slicer. Variables are commonly referred to as placeholders in slicers, no doubt for some obscure historical reason. This means every slicer implementation has its own dialect of placeholders.

    In Cura gcode, you can use placeholder names (variables) by enclosing them in curly braces ({}). Here are some common examples:
    Placeholder Setting
    {material_bed_temperature_layer_0} 1st layer bed temperature
    {material_print_temperature_layer_0} 1st layer nozzle temperature
    {line_width} Extrusion width
    {layer_height} Layer height
    {material_diameter} Filament diameter
    {machine_height} Maximum z height
    Most slicers can't do any assignment of variables or calculations. PrusaSlicer has a very limited set of calculations (min, max, basic math). It's important to keep in mind that any such calculations are done at slice time, not at print time. The slicer does the math and substitutes values for placeholders.

    If you're interested, I've documented my Cura gcode here. The notes are not complete but should give you an idea of what's possible. There's a complete list of Cura placeholders here.

    Comment


    • #3
      Ender5r, Try looking at this. https://github.com/Ultimaker/Cura/bl...aryOfDoom.json
      I used it to shorten the preheating cycle while it is developing the 5x5 mesh for BLTouch bed height compensation.

      Here is an example of what I added to my Start G-Code:
      M190 S{material_bed_temperature}; Wait for bed to heat up



      Last edited by rsonnicksen; 05-02-2021, 09:44 PM.

      Comment


      • #4
        I find this very interesting. I really want to learn how to play with my g code without causing major problems and getting good results. Have they written a 'g code for Dummies yet' ?

        Comment


        • #5
          roon4660 - I haven't seen a good tutorial at the "dummies" level yet. I've put together some notes based on what I've encountered with different slicers, but they're far from complete. A good place to start is the Marlin reference, assuming your printer is based on Marlin. Not every printer is, and individual implementations vary in how complete they are. Unfortunately, it's often hard to get information from the manufacturer on exactly what they support.

          It's pretty common to modify the start gcode routine used by the printer to home, heat the nozzle & bed, and prepare for printing. For example, on early Prusa Mk3 printers the bed leveling sensor was sensitive to temperature, so a routine to warm the sensor was a good starting point. Then modifying the prime line to reduce stinging. Some people had fun getting the prime line to draw little patterns, though the novelty of waiting for every print quickly wore off.

          A bit of custom code is also handy for things like modifying settings (temperature, linear advance settings) during a print for things like test towers where changing values throughout the print based on height is wanted.

          Comment


          • #6
            Originally posted by rsonnicksen View Post
            Ender5r, Try looking at this. https://github.com/Ultimaker/Cura/bl...aryOfDoom.json
            I used it to shorten the preheating cycle while it is developing the 5x5 mesh for BLTouch bed height compensation.

            Here is an example of what I added to my Start G-Code:
            M190 S{material_bed_temperature}; Wait for bed to heat up
            Thanks rsonnicksen. The problem is, when I put a line like that in my Start Code, then slice the model, the resulting g-code contains exactly the same line as what I entered. IOW, it does not get resolved to the temperature I entered in Print Settings. I assume this is not what's supposed to happen.

            Comment


            • #7
              OK, I just sliced a recent model after inserting M104 S{material_print_temperature} into the Start Code. This time (I have zero idea why) it did resolve the variables. To double check, I changed the value in Print Settings to 333. It again resolved.

              So, I'm puzzled. Why did it refuse to resolve variables before & now it does. Truly weird.

              Comment


              • rsonnicksen
                rsonnicksen commented
                Editing a comment
                Maybe it has something to do with variable substitution - on the link I sent you, you can see that there is some logic to substitute other variables if certain slicer settings aren't being used. Or could it be you referenced a variable that was incompatible with the GCode command you were using? I really don't know. I haven't had problems so haven't spent any time troubleshooting. Keep googling and you might find the answer. But glad you got it working for now.

              • rsonnicksen
                rsonnicksen commented
                Editing a comment
                Maybe it has something to do with variable substitution - on the link I sent you, you can see that there is some logic to substitute other variables if certain slicer settings aren't being used. Or could it be you referenced a variable that was incompatible with the GCode command you were using? I really don't know. I haven't had problems so haven't spent any time troubleshooting. Keep googling and you might find the answer. But glad you got it working for now.

            • #8
              Thank you Bobstro I will follow this up later. For now I am drinking a glass of wine and smoking a substance that used to be illegal but I can get same day delivery of it now from the Canadian government or however the new deal works. I order on the internet and get it the same day. Oh how times do change! I must admit that I have not enjoyed the lock-down since it ruined my vacation in the Dominican Republic. I go on youtube to see how things are going in Sosua Dom. Rep. and I can see that a third world dictatorship is dealing with it better than the Western Powers as they wish to be known.
              Sosua one on youtube.com is a good resource.
              My family that lives in the West Indies can't come as they had planned to see my new grandchild. My son and my grandson were supposed to come and live for awhile in montreal while my grandson went to school. I am more than a little pissed with the politics involved in this Plandemic.

              Comment


              • #9
                Originally posted by Ender5r View Post
                OK, I just sliced a recent model after inserting M104 S{material_print_temperature} into the Start Code. This time (I have zero idea why) it did resolve the variables. To double check, I changed the value in Print Settings to 333. It again resolved.

                So, I'm puzzled. Why did it refuse to resolve variables before & now it does. Truly weird.
                Maybe the variables are only used for the internal gcode generator and not in start and end stuff. Or they are only for the post processing stuff.

                Comment


                • #10
                  Originally posted by bobstro View Post
                  roon4660 - I haven't seen a good tutorial at the "dummies" level yet. I've put together some notes based on what I've encountered with different slicers, but they're far from complete. A good place to start is the Marlin reference, assuming your printer is based on Marlin. Not every printer is, and individual implementations vary in how complete they are. Unfortunately, it's often hard to get information from the manufacturer on exactly what they support.

                  It's pretty common to modify the start gcode routine used by the printer to home, heat the nozzle & bed, and prepare for printing. For example, on early Prusa Mk3 printers the bed leveling sensor was sensitive to temperature, so a routine to warm the sensor was a good starting point. Then modifying the prime line to reduce stinging. Some people had fun getting the prime line to draw little patterns, though the novelty of waiting for every print quickly wore off.

                  A bit of custom code is also handy for things like modifying settings (temperature, linear advance settings) during a print for things like test towers where changing values throughout the print based on height is wanted.
                  How do you add "custom code" that affects settings during the middle of a print? Is there a place where I can execute Gcode at each layer, or some interval during the print?

                  Comment


                  • #11
                    Ender5r - Unfortunately, every slicer has different names for these settings. If you are using a slicer that is not Cura, be sure to use the appropriate dialect. Placeholder names and syntax you find for another slicer are unlikely to work. I've found that spacing is also important. Be aware that {material_print_temperature} is the temperature used for the bulk of the print. For your start gcode, you probably want {material_bed_temperature_layer_0} which is the 1st layer filament temperature if you are using a different setting for adhesion. More details on Cura placeholders can be found here.

                    Geit - The placeholders are evaluated by the slicer at slice time. When the code is written, it contains only text. It will replace each placeholder with its respective value in your settings. There is no interpretation of placeholders in the actual printer firmware. The start gcode inserted into your gcode file by the slicer is sent verbatim to the printer.

                    Comment


                    • #12
                      Originally posted by roon4660 View Post
                      [...] For now I am drinking a glass of wine and smoking a substance that used to be illegal but I can get same day delivery of it now from the Canadian government or however the new deal works.
                      It is indeed strange seeing a dispensary being built just up the road in my little town. Talk about a cultural shift!

                      [...] I must admit that I have not enjoyed the lock-down since it ruined my vacation in the Dominican Republic.
                      It has definitely been a strange year, but we do seem to be seeing light at the end of the tunnel. I just hope we can take care of the rest of the world, particularly since this has only been a taste of what could happen in a worst case scenario. Not taking lessons from all this fumbling would be a tragedy!

                      Comment


                      • #13
                        They always say correctly, take care of yourself first do that you can take care of others.

                        Comment


                        • #14
                          Originally posted by Geit View Post

                          Maybe the variables are only used for the internal gcode generator and not in start and end stuff. Or they are only for the post processing stuff.
                          Except the command was inserted into the Cura Start Code section, & this time it worked.

                          Comment


                          • #15
                            Originally posted by rsonnicksen View Post

                            How do you add "custom code" that affects settings during the middle of a print? Is there a place where I can execute Gcode at each layer, or some interval during the print?
                            There is an ChangeAtZ extension to Cura that will let you change a number of settings at either a specific height or specific layer.

                            Comment

                            Working...
                            X