neveroddoreven
Posts: 7
Joined: Tue Aug 12, 2014 7:47 pm

Execute terminal commands after the print finishes/stops

In the Process configuration window's scripts tab, there already exists a post-processing feature to execute a terminal/command after g-code generation has completed. Can this functionality be replicated for two more states?

I would like to invoke a command/terminal executable just prior to starting the print. For example, I wish to call cURL.exe or similar with arguments that tells a home automation device to turn on the mains power to my printer PSU, and perhaps also to turn on an exhaust fan.

I would also like to invoke a command/terminal executable immediately after the print has terminated. If S3D is aware of the termination mode, it would be awesome if that could be passed in via environmental variable (for example, it would be useful to know if the print has successfully completed, versus an abnormal termination due to filament depletion, thermistor problem, printer unresponsiveness, etc.). For example, I wish to call cURL.exe or similar with arguments that tells a home automation device to evaluate some other factors and possibly turn off the mains power to my printer PSU after the print terminates, depending on the termination mode.

EDIT: For those not using home automation, this sort of script could also be used with your favorite command utilities to start a camera stream at the beginning of a print, and play a sound or send an email/text message when your print has finished.
Last edited by neveroddoreven on Sat Jun 06, 2015 7:14 pm, edited 1 time in total.
User avatar
DarthRevan
Posts: 480
Joined: Wed Feb 18, 2015 8:29 am

Re: Execute terminal commands after the print finishes/stops

This would be really interesting. Home automation is, by itself, incredibly neat.
neveroddoreven
Posts: 7
Joined: Tue Aug 12, 2014 7:47 pm

Re: Execute terminal commands after the print finishes/stops

Yeah, it can be a time suck but really rewarding when it works. My printer is currently only tied into the system by means of a smoke/CO alarm that will immediately cut the printer power if smoke is detected.
KC_703
Posts: 238
Joined: Tue Aug 26, 2014 5:23 pm

Re: Execute terminal commands after the print finishes/stops

I've been using a motion sensor to turn off the printer after a certain period of inactivity. The motion sensor sits under my print bed, when it stops moving a script is kicked off to turn the machine off after 20mins. Its saved a lot of late nights waiting for prints to end in the early morning.

PS - also have a smoke/co alarm in the enclosure to shut down the printer on a fire... but I guess that's only half the battle. :)
BaudR8
Posts: 183
Joined: Fri Aug 29, 2014 9:59 am

Re: Execute terminal commands after the print finishes/stops

depending on the firmware/electronics set up, you may be able to do this. For example, if you have Marlin Firmware:

http://reprap.org/wiki/G-code#M42:_Switch_I.2FO_pin
Example: M42 P7 S255
M42 switches a general purpose I/O pin. Use M42 Px Sy to set pin x to value y, when omitting Px the LEDPIN will be used.
Seems like it will allow you to toggle a gpio pin, so you can edit the ending gcode to toggle an unused GPIO pin and then attach that to your home automation microcontroller
david-hunter
Posts: 5
Joined: Sat May 23, 2020 12:07 am

Re: Execute terminal commands after the print finishes/stops

This would be a hugely useful feature.

I realise it won't be feasible when saving the gcode files to an SD card, but when controlling the 3D printer directly in S3D, S3D certainly knows when a print has finished (or it should be trivial to know, given that it communicates with the printer in real-time). Therefore, it should be fairly straightforward to run a terminal command once a print is complete.

I'd love to be able to use cURL to send myself an SMS via Twilio, for example, and then turn off my Philips Hue lights and cut power to the printer, all automatically once a print is finished.
david-hunter
Posts: 5
Joined: Sat May 23, 2020 12:07 am

Re: Execute terminal commands after the print finishes/stops

david-hunter wrote: Wed Sep 30, 2020 6:29 am This would be a hugely useful feature.

I realise it won't be feasible when saving the gcode files to an SD card, but when controlling the 3D printer directly in S3D, S3D certainly knows when a print has finished (or it should be trivial to know, given that it communicates with the printer in real-time). Therefore, it should be fairly straightforward to run a terminal command once a print is complete.

I'd love to be able to use cURL to send myself an SMS via Twilio, for example, and then turn off my Philips Hue lights and cut power to the printer, all automatically once a print is finished.
Turns out you can do this if you use Octoprint. I use S3D to create a gcode file, which then gets uploaded to Octoprint (a web server which controls the printer itself). This is done using an Octoprint plugin called "GCODE System Commands". Hope this helps someone.
maz
Posts: 1
Joined: Thu Dec 24, 2020 9:12 am

Re: Execute terminal commands after the print finishes/stops

I would really love this feature also. I currently have to watch my printer remotely with a webcam and then turn off power and fans via a web interface. It would be nice for it to be able to do this automatically. I can write programs or use cURL to achieve this goal if there was a way to trigger it from simplify3d.

+1
simplify_user001
Posts: 2
Joined: Tue Apr 20, 2021 7:42 am

Re: Execute terminal commands after the print finishes/stops

Hi

Did you find a way to run a command with a trigger from Simplify3D?
david-hunter
Posts: 5
Joined: Sat May 23, 2020 12:07 am

Re: Execute terminal commands after the print finishes/stops

Not with S3D, no. Instead, I set up an Octoprint instance on a Raspberry Pi, and there's a plugin for that which allows running BASH commands.

Return to “Feature Requests”