Send gcode commands programatically

I've been searching through the documentation but I can't see how to issue gcode commands directly to the printer. For example, I'd like to do something like this:

def some_func():
   printer.command("M80")   # pseudo-code

Is there a mixin or anything to do this? I see there's an octoprint.printer.factory but I'm not really sure if it's what I'm looking for or how to use it.

Hmmm... Looking at examples, it seems you can access the printer like so:

def some_func(self):
    self._printer.command("M80")
1 Like

Yep, that's one way. You can also do it from the javascript side.

1 Like