Trying to write new plugin, need API to get gcode

Hi devs,

I'm currently writing on a Plugin that wraps the STL-Tweaker (autorotation module) and the Slic3r and it should be external.
https://github.com/ChristophSchranz/Octoprint-PrePrintService (no doc yet)

It works, but I still have problems to handle the gcode_name path. I look for an API to fetch the name from the slic3r html, with the profile it runs with:
profile_dict, display_name, description = self._load_profile(profile_path)
print(display_name)

At the moment I send a request.post to the external server, that processes the file and request.post back the gcode (with a default name now). Afterwards a second .gco-file is created, which is a one-liner..
Is there a smoother way to only return a single file that has the correct name?

Best regards,
Chris

You'll want to use the filemanager.preprocessor hook documented here. I use it in my CustomBackground plugin to move the uploaded image file into a different directory, as seen in the link here. Hopefully that helps you out.

Thank you for your answer.
Unfortunately not. My preprocessing functionality is for autorotating and slicing. My problem is that I can't extract the selected name of the future machinecode. The problem lies in the filemanager/init(), where the real destinal_path is overwritten by a random one:

		f = tempfile.NamedTemporaryFile(suffix=".gco", delete=False) # Why?????
		temp_path = f.name

As a result, the name I get is of the form "tmpuHMJ2L.gco" and I have to name the gcode manually by a static pattern.
Is there any workaround to get the desired name from the webinterface.

Oh, then you should look into the event hooks maybe. Specifically file-handling event with the EventHandlerPlugin mixin. Something like...

def on_event(self, event, payload):
	if event == "FileAdded":
		# do work using payload.path here
1 Like

Thank you very much! :slight_smile:

I could retrieve the filename with:

	# EventPlugin
	def on_event(self, event, payload):
		if event == "SlicingStarted":
			self.machinecode_name = payload.get("gcode", None)