Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    conditional g-code, alternative to curly braces?

    Scheduled Pinned Locked Moved Solved
    Gcode meta commands
    4
    7
    659
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • garyd9undefined
      garyd9
      last edited by

      Is there an alternative pair of characters that can be used in conditional g-code instead of curly braces?

      My reason for asking is that having curly braces in Cura's machine start g-code can break cura's setting replacement. As a real example, the following in my cura startup-gcode works as expected:

      G10 L2 P2 X{retraction_amount} Y{retraction_speed} Z{retraction_prime_speed} ; put retraction settings in workspace2
      

      ...results in the following being written to the gcode file:
      G10 L2 P2 X0.6 Y50 Z20

      However, if I put the following two lines in the cura start g-code, it appears that cura gets confused by unrecognized tokens in curly braces, and therefore refuses to do ANY substitution at all:

      G10 L2 P2 X{retraction_amount} Y{retraction_speed} Z{retraction_prime_speed} ; put retraction settings in workspace2
      M207 S{move.axes[0].workplaceOffsets[1]} R0 F{move.axes[1].workplaceOffsets[1] * 60} T{move.axes[2].workplaceOffsets[1] * 60}
      

      ... resulting in the above two lines being copied to the gcode exactly as typed above without replacing "retraction_amount", etc (making it useless.)

      At the moment, I'm working around this issue by putting the M207 call into a macro file, and then calling the macro from the start gcode.

      "I'm not saying that you are wrong - I'm just trying to fit it into my real world simulated experience."

      1 Reply Last reply Reply Quote 1
      • T3P3Tonyundefined
        T3P3Tony administrators
        last edited by

        @garyd9 that's a tricky one. No doubt you have seen that sub expressions in conditional gcode can use () brackets instead (but that does not help here).

        I tried a few ideas in Cura to escape those characters but that did not help, you can see in the cura log files it gives up;

        2021-03-01 23:48:08,310 - WARNING - [Thread-8] UM.Logger.logException [106]: Exception: Unable to do token replacement on start/end g-code
        2021-03-01 23:48:08,313 - WARNING - [Thread-8] UM.Logger.logException [110]: Traceback (most recent call last):
        2021-03-01 23:48:08,315 - WARNING - [Thread-8] UM.Logger.logException [110]:   File "C:\Program Files\Ultimaker Cura 4.8.0\plugins\CuraEngineBackend\StartSliceJob.py", line 395, in _expandGcodeTokens
        2021-03-01 23:48:08,318 - WARNING - [Thread-8] UM.Logger.logException [110]:     return str(fmt.format(value, **settings))
        2021-03-01 23:48:08,320 - WARNING - [Thread-8] UM.Logger.logException [110]:   File "string.py", line 191, in format
        2021-03-01 23:48:08,322 - WARNING - [Thread-8] UM.Logger.logException [110]:   File "string.py", line 195, in vformat
        2021-03-01 23:48:08,324 - WARNING - [Thread-8] UM.Logger.logException [110]:   File "string.py", line 235, in _vformat
        2021-03-01 23:48:08,326 - WARNING - [Thread-8] UM.Logger.logException [110]:   File "string.py", line 306, in get_field
        

        One option that might be worth exploring is using the post processing script to run a search replace on a comment line or similar to generate that line for you. but the macro solution is easier!

        www.duet3d.com

        1 Reply Last reply Reply Quote 0
        • OwenDundefined
          OwenD
          last edited by

          This is one of the reasons I abandoned Cura in favour of PrusaSlicer.
          You could maybe put all your RRF stuff in a special character that replaces the curly braces (like #move.axes[0].min~) and then run two search and replace post processing scripts to replace it with curly brackets again.

          M207 S#move.axes[0].workplaceOffsets[1]~ R0 F#move.axes[1].workplaceOffsets[1] * 60~ T#move.axes[2].workplaceOffsets[1] * 60~
          

          step1.jpg
          step2.jpg

          Output becomes

          M207 S{move.axes[0].workplaceOffsets[1]} R0 F{move.axes[1].workplaceOffsets[1] * 60} T{move.axes[2].workplaceOffsets[1] * 60}
          
          
          OwenDundefined 1 Reply Last reply Reply Quote 1
          • OwenDundefined
            OwenD @OwenD
            last edited by

            @OwenD
            Actually # is a bad example to use as it's used in RRF meta commands but you get the idea

            1 Reply Last reply Reply Quote 1
            • dc42undefined
              dc42 administrators
              last edited by

              Just a thought: have you tried:

              M207 S{{move.axes[0].workplaceOffsets[1]}} R0 F{{move.axes[1].workplaceOffsets[1] * 60}} T{{move.axes[2].workplaceOffsets[1] * 60}}
              

              or:

              M207 S{(move.axes[0].workplaceOffsets[1])} R0 F{(move.axes[1].workplaceOffsets[1] * 60)} T{(move.axes[2].workplaceOffsets[1] * 60)}
              

              Duet WiFi hardware designer and firmware engineer
              Please do not ask me for Duet support via PM or email, use the forum
              http://www.escher3d.com, https://miscsolutions.wordpress.com

              OwenDundefined garyd9undefined 2 Replies Last reply Reply Quote 2
              • OwenDundefined
                OwenD @dc42
                last edited by

                @dc42 said in conditional g-code, alternative to curly braces?:

                Just a thought: have you tried:

                M207 S{{move.axes[0].workplaceOffsets[1]}} R0 F{{move.axes[1].workplaceOffsets[1] * 60}} T{{move.axes[2].workplaceOffsets[1] * 60}}
                

                Nailed it!

                G10 L2 P2 X{retraction_amount} Y{retraction_speed} Z{retraction_prime_speed} ; put retraction settings in workspace2
                M207 S{{move.axes[0].workplaceOffsets[1]}} R0 F{{move.axes[1].workplaceOffsets[1] * 60}} T{{move.axes[2].workplaceOffsets[1] * 60}} 
                

                Gives this output in Cura 4.6.1

                G10 L2 P2 X3 Y20.0 Z20.0 ; put retraction settings in workspace2
                M207 S{move.axes[0].workplaceOffsets[1]} R0 F{move.axes[1].workplaceOffsets[1] * 60} T{move.axes[2].workplaceOffsets[1] * 60} 
                
                

                The second example fails to process both lines.

                1 Reply Last reply Reply Quote 0
                • garyd9undefined
                  garyd9 @dc42
                  last edited by

                  @dc42 said in conditional g-code, alternative to curly braces?:

                  M207 S{{move.axes[0].workplaceOffsets[1]}} R0 F{{move.axes[1].workplaceOffsets[1] * 60}} T{{move.axes[2].workplaceOffsets[1] * 60}}
                  

                  I can confirm that doubling the curly braces does appear to work. Thank you.

                  Gary

                  "I'm not saying that you are wrong - I'm just trying to fit it into my real world simulated experience."

                  1 Reply Last reply Reply Quote 1
                  • First post
                    Last post
                  Unless otherwise noted, all forum content is licensed under CC-BY-SA