Skip to content

Setting up and using parametric macros using OctoPrint and various plugins

License

Notifications You must be signed in to change notification settings

CmdrCody51/OctoPrint-Parametric-Macros

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OctoPrint-Parametric-Macros

Setting up and using parametric macros using OctoPrint and various plugins. Along with other hints and tricks.

Select and install the plugins

Run, don't walk, to https://plugins.octoprint.org/ and get:

  • GCode Macros https://github.com/cp2004/OctoPrint-GcodeMacros
    OctoPrint Gcode Macros Plugin Create custom commands you can add anywhere: in your gcode file, OctoPrint’s terminal, gcode scripts, or other plugins to run a configured script.
    Use macros for preheating your printer, levelling the bed, changing filament… Possibilities are (nearly) endless!

  • GCode Systems Commands https://github.com/kantlivelong/OctoPrint-GCodeSystemCommands
    This OctoPrint plugin adds the ability to define GCode commands that execute local system commands.

  • You can also use this plugin(maybe)

  • Custom Control Editor https://plugins.octoprint.org/plugins/customControl/
    Makes custom controls editable via the settings dialog.
    This plugin helps you create, edit and delete your custom controls. You can easily access all the options in the settings under “Custom Control Editor”.

  • Also extremely helpful
  • For Marlin firmware: https://marlinfw.org/meta/gcode/
  • For RepRap firmware and somewhat for Klipper: https://reprap.org/wiki/G-code
  • The Magic

    Ok, first, I walked away from using Microsoft products in 2004 or so and have never looked back (except to laugh!)
    If you want to do this on Windows (without loading up some Linux compatability programs) you are on your own...
    That being said - Welcome!

    Note:
    To save yourself some heartache, place ALL your bash shell scripts in "/home/$USER/.octoprint/scripts/"
    Why?
    The directory is backed up and restored with OctoPrint Backup command! I even put my boot and crontab files there.

    This is only a quick review with no real instructions

    Here is my Controls Page using Custom Control Editor

    That's a lot of stuff! Need it? No. But it is what led me down this rabbit hole...
    And this is the little trick it taught me!

    This is configured in Custom Control Editor plugin.

    This was derived from GCode Systems Commands plugin.
    (See the stuff in red at the bottom?)

    So it calls "Variable.sh"

    #!/bin/bash
    # this is to give OP something to call
    # full paths required
    # $OCTOPRINT_GCODESYSTEMCOMMAND_ID="400"
    # $OCTOPRINT_GCODESYSTEMCOMMAND_ARGS="File=WhyMe.data Name=mine.my_flag Value=true"
    # $OCTOPRINT_GCODESYSTEMCOMMAND_LINE="OCTO400 File=WhyMe.data Name=mine.my_flag Value=true"
    
    # my_string="File=WhyMe.data Name=mine.my_State Value=false"
    my_string="$OCTOPRINT_GCODESYSTEMCOMMAND_ARGS"
    
    # Strip each part of the string
    # break at 'space'
    my_file=${my_string%%' '*}
    # delete the part captured
    my_newstring=${my_string/$my_file/}
    # break that at '='
    my_file=${my_file##*'='}
    # delete the leading space
    my_newstring=${my_newstring/# /}
    # rinse and repeat for all
    my_name=${my_newstring%%' '*}
    my_newstring=${my_newstring/$my_name/}
    my_name=${my_name##*'='}
    my_newstring=${my_newstring/# /}
    #my_value=${my_newstring%%' '*}
    my_value=${my_newstring##*'='}
    
    # sed -i 's/true/false/' /home/pi/.octoprint/data/gcode_macro/my_Logic.flag
    # {% set mine.my_State = true %}
    
    orig="{%- set $my_name = "
    rep="{%- set $my_name = $my_value -%}"
    
    cmd="/usr/bin/sed -i 's/$orig.*/$rep/' /home/pi/.octoprint/data/gcode_macro/$my_file"
    # echo "File is: $my_file"
    # echo "Name is: $my_name"
    # echo "Value is: $my_value"
    
    ## /usr/bin/echo "$my_string" >> /home/pi/ShowMe
    ## /usr/bin/echo "$cmd" >> /home/pi/ShowMe
    eval $cmd
    
    exit
    

    Specifically, this lets me edit my runtime variables file from the Control Tab.
    It also lets me edit them from the Gcode file!
    For example:

    ;TYPE:Custom
    ; custom gcode: start_gcode
    
    ; Inserted from post processor script in SuperSlicer that converts a text file of
    ; layer based actions manually entered from the slicers preview screen.
    
    OCTO400 File=WhyMe.data Name=mine.my_LayerCount Value=0
    OCTO400 File=WhyMe.data Name=mine.my_LayerMatch Value=0
    OCTO400 File=WhyMe.data Name=mine.my_Layer Value=0
    OCTO400 File=WhyMe.data Name=mine.my_State Value=false
    OCTO401
    OCTO402 Name=64 Value="Place O-Ring"
    
    ; The only action is to place an O-Ring at the start of layer 65 (see notes)
    ; I always stop after Layer 1 cause I ain't gonna print with a shitty first layer.
    
    M117 ARC_WELD ; post processing flag if printer can do G02/G03
    ; leave above as some post processors can remove comments
    
    ; This trips my ArcWelder script post processor
    
    G21 ; my set units to millimeters
    G90 ; my use absolute coordinates
    M82 ; my use absolute distances for extrusion
    [...]
    ; custom gcode: start_filament_gcode
    ;Filament gcode
    ; extruder Black PLA
    ; custom gcode end: start_filament_gcode
    ;_TOOLCHANGE 0
    ;LAYER_CHANGE
    ;Z:0.2
    ;HEIGHT:0.2
    ; custom gcode: before_layer_gcode
    ; Before layer change
    OCTO100
    G4 P500
    ; This is my Tool change Servo based, I give it 1/2 second to complete
    G1 F200 E25
    M400
    G92 E0
    OCTO400 File=WhyMe.data Name=mine.my_LayerFR Value=200
    ; Another post processor script looks for every @DoLayer line and saves the current Feedrate
    ; in case I mess with it.
    @DoLayer
    ; @DoLayer does everything. If I want timelapse or an action at a layer. All set with flags
    ; in the WhyMe.data file.
    ; custom gcode end: before_layer_gcode
    [...]
    ;TYPE:Skirt
    

    My Data File
    {%- set mine.my_Working = false -%} {%- set mine.my_State = false -%} {%- set mine.my_Pause = true -%} {%- set mine.my_BedTemp = 70 -%} {%- set mine.my_HeadType = 0 -%} {%- set mine.my_HotendTemp = 200 -%} {%- set mine.my_HotendMinTemp = 160 -%} {%- set mine.my_Feedrate = 100 -%} {%- set mine.my_Flowrate = 100 -%} {%- set mine.my_T0WT = [10,190] -%} {%- set mine.my_T1WT = [20,190] -%} {%- set mine.my_T2WT = [30,190] -%} {%- set mine.my_T3WT = [40,190] -%} {%- set mine.my_PreFeed = 570 -%} {%- set mine.my_MaxExt = 200 -%} {%- set mine.my_ABL = false -%} {%- set mine.my_TimeLapse = false -%} {%- set mine.my_Z_Lift = 3.5 -%} {%- set mine.my_Fix_Zon = 0.125 -%} {%- set mine.my_Fix_Zoff = 2.0 -%} {%- set mine.my_Retract = 5 -%} {%- set mine.my_TLPts = [5,215] -%} {%- set mine.my_Delay = 0 -%} {%- set mine.my_LayerCount = 42 -%} {%- set mine.my_Layer = 64 -%} {%- set mine.my_LayerMatch = 1 -%} {%- set mine.my_LayerFR = 7800 -%} {%- set mine.my_Levels = [] -%} {%- set mine.my_BedLevelCnt = 0 -%}

    That was a little taste

    Each subdirectory contains my code and explains how it is used and how it is related to the other parts of my "system" (I am so funny). Enjoy!

    Ko-Fi or GitHub Use GitHub!

    You can also send funds via PayPal to cmdrcody@pharowt.com

    About

    Setting up and using parametric macros using OctoPrint and various plugins

    Resources

    License

    Stars

    Watchers

    Forks

    Releases

    No releases published

    Packages

    No packages published