Generate a gcode string from a list of steps. Args: steps (list): A list of step objects. gcode_controls (GcodeControls, optional): An instance of GcodeControls class. Defaults to GcodeControls(). Returns: str: The generated gcode string.
(steps: list, gcode_controls: GcodeControls, show_tips: bool)
| 10 | |
| 11 | |
| 12 | def gcode(steps: list, gcode_controls: GcodeControls, show_tips: bool): |
| 13 | ''' |
| 14 | Generate a gcode string from a list of steps. |
| 15 | |
| 16 | Args: |
| 17 | steps (list): A list of step objects. |
| 18 | gcode_controls (GcodeControls, optional): An instance of GcodeControls class. Defaults to GcodeControls(). |
| 19 | |
| 20 | Returns: |
| 21 | str: The generated gcode string. |
| 22 | ''' |
| 23 | gcode_controls.initialize() |
| 24 | if show_tips: tips(gcode_controls) |
| 25 | |
| 26 | state = State(steps, gcode_controls) |
| 27 | # need a while loop because some classes may change the length of state.steps |
| 28 | while state.i < len(state.steps): |
| 29 | # call the gcode function of each class instance in 'steps' |
| 30 | gcode_line = state.steps[state.i].gcode(state) |
| 31 | if gcode_line != None: |
| 32 | state.gcode.append(gcode_line) |
| 33 | state.i += 1 |
| 34 | gc = '\n'.join(state.gcode) |
| 35 | |
| 36 | if gcode_controls.save_as != None: |
| 37 | filename = gcode_controls.save_as |
| 38 | filename += datetime.now().strftime("__%d-%m-%Y__%H-%M-%S.gcode") if gcode_controls.include_date == True else '.gcode' |
| 39 | open(filename, 'w').write(gc) |
| 40 | |
| 41 | return gc |
no test coverage detected