Is there a way to query CP for estimatedPrintTime?

Is there a way to query CP for estimatedPrintTime?

Yes, take a look at how the Gcode widget grabs that data. So go and fork the Gcode widget and look at the getEstimates() method on line 328. It’s actually querying the 3D viewer via ChiliPeppr’s pubsub.

Epic. Thanks.

getEstimates: function() {
var that = this;
this.get3dObj(function() {
// when we get this callback, we should have a 3dobj
console.log(“getEstimates got obj3d:”, this.obj3d);
if (this.obj3d && this.obj3d.userData && this.obj3d.userData.lines) {
var lastLine = this.obj3d.userData.lines[this.obj3d.userData.lines.length - 1];
if (‘p2’ in lastLine && ‘timeMinsSum’ in lastLine.p2) {
console.log(“we got a timeMinsSum:”, lastLine.p2.timeMinsSum);
var estDurMins = lastLine.p2.timeMinsSum;
var str = this.toHHMMSS(estDurMins * 60); // expect seconds
$(‘#com-chilipeppr-widget-gcodeviewer #gcode-time-est’).text(str);
}
}
});
},
userCallbackForGet3dObj: null,
get3dObj: function (callback) {
this.userCallbackForGet3dObj = callback;
chilipeppr.subscribe(“/com-chilipeppr-widget-3dviewer/recv3dObject”, this, this.get3dObjCallback);
chilipeppr.publish(“/com-chilipeppr-widget-3dviewer/request3dObject”, “”);
chilipeppr.unsubscribe(“/com-chilipeppr-widget-3dviewer/recv3dObject”, this.get3dObjCallback);
},
get3dObjCallback: function (data, meta) {
console.log(“got 3d obj:”, data, meta);
this.obj3d = data;
this.obj3dmeta = meta;
if (this.userCallbackForGet3dObj) {
//setTimeout(this.userCallbackForGet3dObj.bind(this), 200);
//console.log(“going to call callback after getting back the new 3dobj. this.userCallbackForGet3dObj:”, this.userCallbackForGet3dObj);
this.userCallbackForGet3dObj();
this.userCallbackForGet3dObj = null;
}
},