GCODE Viewer API


#1

I was wondering if there is an API interface to get the GCODE viewer to show the file that is being printed or if a javascript code is available to integrate in an app

Thanks


#2

this do? http://docs.octoprint.org/en/master/api/job.html#retrieve-information-about-the-current-job


#3

I just used my octo-client software from npmjs.com to quickly query the currently-running job's filename using NodeJS. I assume that you have Node and npm installed:

cd sites
mkdir octo-getjob && cd octo-getjob
touch octo-getjob
chmod a+x octo-getjob
npm init    # When asked for the entry point, indicate "octo-getjob"
npm install --save octo-client
nano node_modules/octo-client/config.js # Edit as necessary with your API key
nano octo-getjob

octo-getjob contents:

#!/usr/bin/env node

var OctoPrint = require('octo-client');

OctoPrint.job(function(response){
  console.log(response.job.file.name);
});
./octo-getjob
# Displays "pizero-case-parts-nocutout.gcode"

#4

I am looking for an API that can actually show the graphic of the GCODE just like in ../#gcode view so that I can embed that in my web page


#5

Oh...

I could think of three approaches.

  1. Copy the existing code to create just the content you want and make your own API endpoint
  2. Create a script which does a curl of the Gcode tab page and then remove the HTML that you're not interested in.
  3. Create a proxy which does this

#6

Could you give an example of the approaches, that will help


#7

Any of the above would be a fair amount of work, to be honest. I attempted to determine a quick-and-dirty method of using awk at the command line to pare down the page but it's not something that would be easy.

Perhaps others would like to take on the challenge.