return a gcode string generated from a list of steps
(steps: list, gcode_controls: GcodeControls = GcodeControls())
| 6 | |
| 7 | |
| 8 | def gcode(steps: list, gcode_controls: GcodeControls = GcodeControls()): |
| 9 | 'return a gcode string generated from a list of steps' |
| 10 | if gcode_controls.b_offset_z == None: |
| 11 | raise Exception( |
| 12 | "gcode generation requires an fc4.GcodeControls object to be supplied with the attribute 'b_offset_z' set correctly") |
| 13 | state = State(steps, gcode_controls) |
| 14 | # need a while loop because some classes may change the length of state.steps |
| 15 | while state.i < len(state.steps): |
| 16 | # call the gcode function of each class instance in 'steps' |
| 17 | gcode_line = state.steps[state.i].gcode(state) |
| 18 | if gcode_line != None: |
| 19 | state.gcode.append(gcode_line) |
| 20 | state.i += 1 |
| 21 | gc = '\n'.join(state.gcode) |
| 22 | |
| 23 | if gcode_controls.save_as != None: |
| 24 | filename = gcode_controls.save_as + \ |
| 25 | datetime.now().strftime("__%d-%m-%Y__%H-%M-%S.gcode") |
| 26 | open(filename, 'w').write(gc) |
| 27 | else: |
| 28 | return gc |
no test coverage detected