Global variables between macros



  • Is there currently a way to set a global variable from one macro and check it from another? My current work around is to setup a fake FAN port and set it with an "M106 P5 S255" from one macro and then check "fans[5].actualValue" from the other macro. I'm doing this because after I run my "Filament Unload Macro" I would like my "Filament Load" macro to check if the Unload macro has already been run. My current method seems hackish at best 🙂



  • Might be hackish but very clever 🙂



  • I love the solution! It's a shame it won't work with DSF (yet?)



  • Found a slightly better way to transfer info between macros. Using the same fake fan port you can change the name with an M106 P5 C"NewName" or even an C{Object.Model} as the name. Then recall that information back in another macro or even later in the same gcode.

    edit:The below example wont work, the M220 command won't accept {fans[5].name} as an input since its been converted to a string. I'm going to leave it here in case anyone has other ideas

    One example I can think of this is storing the current speed factor as a Fan name, setting the speed back to 100, then restoring the speed later in the gcode. I'm sure all this will be much easier once actual variables are implemented but until then this seems like a decent workaround.

    ;Setting up the fake Fan in config.g
    M950 F5 C"duex.fan5"
    M106 P5 C"Fake"

    ;Storing the current print Speed Factor as a fan name
    M106 P5 C{move.speedFactor}

    ;Setting Speed Factor to 100%
    M220 S100

    ;Setting the Speed Factor back to what was stored
    M220 S{fans[5].name}

    edit edit: I think this might work with a fake heater and storing the integer you wanted as the max temp using an M143



  • I think passing parameters to M98 is on the to-do list, but interesting workaround while we wait. 👍


Log in to reply