What is wrong with the button that is already there? What do you want to do that can not be done in the same way that for example the Z Offset plugin acts on the gcode?
@mafi - did you try the Z offset plugin? I think it has the behavior you want. If not explain what is wrong with that behavior please.
My post processing script is a complet standalone qui where i can modify multi extruder settings for each model for infill. All based on comments in the final gcode.
So i want to do my own export function in cura.
i dont want to do the three extra clicks on slicing, file export ....
espacially i have to save the gcode data twice to disk. First before postprocessing and after.
Would be very nice to grap the mesh stream from export and a custom button in gui.
It sounds like you want a "post processing plugin". Which is what those examples are above. It's easy (at least it used to be) to have one program be both a plugin and also a standalone. Please look at one of the examples above. We are talking about maybe 5 lines of code to make a standalone program also be a plugin (at least that's how it used to be the last time I looked into "post processing plugins".
I assume you mean it's a CLI standalone and not some fancy gui where you have to click "file open" and such. A standalone CLI program needs to be told where the file to process is located and so on. I believe the post processing plugin gets the data on the input stream? Maybe? I'm not sure. Writing a standalone program that can do either is pretty easy. You don't even need a special option (e.g. "-plug") as the plugin should be able to detect which mode it is being used.
Okay I just looked at some modern post processing plugins. I looked at the 2 by fieldofview and I looked at this one:
https://github.com/Ultimaker/Cura/blob/master/plugins/PostProcessingPlugin/scripts/PauseAtHeight.py
And it is definitely more than 5 lines of code (legacy cura was much simpler).
But it's not to hard to separate out the "guts" of the code into a function/functions and call that from either the standalone code or from the plugin version. You can have the "basic business rules" of your plugin in one function or a set of functions and then add one python file for standalone mode and another python file for plugin mode.
I wonder if someone already did this...
from . import Prozessor
from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")
def getMetaData():
return {
"mesh_writer": {
"output": [{
"description": catalog.i18nc("@item:inlistbox", "00MyOWN00"),
"mime_type": "text/00foo00",
"mode": Prozessor.MyOWNGCodeWriter.OutputMode.TextMode
}]
}
}
def register(app):
return {"mesh_writer": Prozessor.MyOWNGCodeWriter()}
from UM.PluginRegistry import PluginRegistry
from UM.Mesh.MeshWriter import MeshWriter
from UM.Application import Application
from UM.Logger import Logger
from typing import cast
import subprocess
import pathlib
class MyOWNGCodeWriter(MeshWriter):
version = 3
def __init__(self):
super().__init__(add_to_recent_files = False)
self._application = Application.getInstance()
def write(self, stream, nodes, mode = MeshWriter.OutputMode.TextMode):
gcode_writer = cast(MeshWriter, PluginRegistry.getInstance().getPluginObject("GCodeWriter"))
success = gcode_writer.write(stream, None)
stream.close()
if not success:
self.setInformation(gcode_writer.getInformation())
return False
this_file_path = pathlib.Path(__file__).parent
exe_path = str(this_file_path.joinpath("Prozessor.exe").absolute())
command = ["cmd", "/c", exe_path, stream.name]
Logger.log("i", "-=-=-=-=-=-=-=-=-=-=> Execute: "+str(" ".join(command)))
process = subprocess.Popen(command)
process.wait()
if process.returncode == 0:
Logger.log("i", "-=-=-=-=-=-=-=-=-=-=> processing was succesfull")
else:
Logger.log("w", "-=-=-=-=-=-=-=-=-=-=> execution failed")
return True
If you delet all the logging its only 5 lines 😉 (maybe more)
Its not big.
How do i get the cast if i am not a export plugin?
cast(MeshWriter, PluginRegistry.getInstance().getPluginObject("GCodeWriter"))
How do i get a button in gui if i am not a tool plugin?
How do i start slicing via code?
5 hours ago, mafi said:How do i get a button in gui if i am not a tool plugin?
Have a look at the Automatic Slicing Toggle plugin:
https://marketplace.ultimaker.com/app/cura/plugins/fieldofview/PauseBackendPlugin
5 hours ago, mafi said:How do i start slicing via code?
From the QML button you could do this:
https://github.com/Ultimaker/Cura/blob/master/resources/qml/ActionPanel/SliceProcessWidget.qml#L40
Or from Python you could do
Application.getInstance().getBackend().forceSlice()
Having said that I still recommend you to implement this in a way that fits better with the normal Cura workflow (adjusting models and settings, slicing, previewing and then saving/printing), instead of going around it. What sort of standalone GUI are you talking about? Could it be integrated into Cura, as a stage? You could have a look at the Teton Smart Slice plugin.
I don't know what a stage in CURA is, so far i trag n drop presliced gcode on my EXE and i can ajust the MultiExtrusion setting for Hight, Infill or change speed at specifig Z hight.
So far i have my Profiles where i dont have to ajust anything.
And up to now i have to click slice, go up to file Export and export the gcode.
When i am finisched i hopefully only click on my Workflow button.
Will have a look on Weekend on your suggestion.
Recommended Posts
ahoeben 2,023
That is not how a tool should work in Cura. The toolbuttons in the toolpanel on the left are meant to activate tools that manipulate the models on the buildplate.
It would be more in line with how Cura works if you add a setting to enable your postprocessing code, like for example the Z Offset and Linear Advance plugins do:
https://github.com/fieldOfView/Cura-ZOffsetPlugin
https://github.com/fieldOfView/Cura-LinearAdvanceSettingPlugin
Those plugins show you how to apply your postprocessing code when the user saves a gcode file (so the file that gets saved is processed).
Link to post
Share on other sites
mafi 0
So maybe not as tool, then a custom button where i can start slicing and grap the mesh stream?
Edited by mafiLink to post
Share on other sites