Jump to content
UltiMaker Community of 3D Printing Experts

call meshwriter as tool


Recommended Posts

Posted · call meshwriter as tool

I want to run my own post processsing script via a nice tool button in cura.
i have it running in file/export ... but this is so much more work 😉
It would be nice to have it on the left side and when i click on and i haven't clicked slice than it starts slicing and when finished it directly starts my srcipt.

I don't want to get a file which i have to pass to my script where i have to read and overwrite.
It should be possible to directly pipe the stream to my scritp so only one time a file is written.

I know its a difficult question, if you need more information pleas let me know.

kind regards

  • Link to post
    Share on other sites

    Posted · call meshwriter as tool
    12 hours ago, mafi said:

    I want to run my own post processsing script via a nice tool button in cura.

    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:



    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).

    • Thanks 1
    Link to post
    Share on other sites

    Posted · call meshwriter as tool

    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?

  • Link to post
    Share on other sites

    Posted (edited) · call meshwriter as tool

    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.

    Edited by mafi
  • Link to post
    Share on other sites

    Posted · call meshwriter as tool

    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.

  • Link to post
    Share on other sites

    Posted · call meshwriter as tool

    Okay I just looked at some modern post processing plugins.  I looked at the 2 by fieldofview and I looked at this one:



    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...

  • Link to post
    Share on other sites

    Posted (edited) · call meshwriter as tool
    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)
    		if not success:
    			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)
    		if process.returncode == 0:
    			Logger.log("i", "-=-=-=-=-=-=-=-=-=-=>  processing was succesfull")
    			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?

    Edited by mafi
  • Link to post
    Share on other sites

    Posted · call meshwriter as tool
    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:



    5 hours ago, mafi said:

    How do i start slicing via code?

    From the QML button you could do this:


    Or from Python you could do



    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.

  • Link to post
    Share on other sites

    Posted · call meshwriter as tool

    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.

  • Link to post
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

    • Our picks

      • Here it is. The new UltiMaker S7
        The UltiMaker S7 is built on the success of the UltiMaker S5 and its design decisions were heavily based on feedback from customers.
        So what’s new?
        The obvious change is the S7’s height. It now includes an integrated Air Manager. This filters the exhaust air of every print and also improves build temperature stability. To further enclose the build chamber the S7 only has one magnetically latched door.
        The build stack has also been completely redesigned. A PEI-coated flexible steel build plate makes a big difference to productivity. Not only do you not need tools to pop a printed part off. But we also don’t recommend using or adhesion structures for UltiMaker materials (except PC, because...it’s PC). Along with that, 4 pins and 25 magnets make it easy to replace the flex plate perfectly – even with one hand.
        The re-engineered print head has an inductive sensor which reduces noise when probing the build plate. This effectively makes it much harder to not achieve a perfect first layer, improving overall print success. We also reversed the front fan direction (fewer plastic hairs, less maintenance), made the print core door magnets stronger, and add a sensor that helps avoid flooding.

        The UltiMaker S7 also includes quality of life improvements:
        Reliable bed tilt compensation (no more thumbscrews) 2.4 and 5 GHz Wi-Fi A 1080p camera (mounted higher for a better view) Compatibility with 280+ Marketplace materials Compatibility with S5 project files (no reslicing needed) And a whole lot more  
        Curious to see the S7 in action?
        We’re hosting a free tech demo on February 7.
        It will be live and you can ask any questions to our CTO, Miguel Calvo.
        Register here for the Webinar
          • Like
        • 10 replies
      • UltiMaker Cura 5.3.0-Alpha 🎄 Tree Support Spotlight 🎄
        Are you a fan of tree support, but dislike the removal process and the amount of filament it uses? Then we would like to invite you to try this special release of UltiMaker Cura. Brought to you by our special community contributor @thomasrahm
        We generated a special version of Cura 5.2 called 5.3.0 Alpha + Xmas. The only changes we introduced compared to UltiMaker Cura 5.2.1 are those which are needed for the new supports. So keep in mind, this is not a sneak peek for Cura 5.3 (there are some really cool new features coming up) but a spotlight release highlighting this new version of tree supports.  
          • Like
        • 16 replies
      • New here? Get ahead with a free onboarding course
        Often getting started is the most difficult part of any process. A good start sets you up for success and saves you time and energy that could be spent elsewhere. That is why we have a onboarding course ready for
        Ultimaker S5 Pro Bundle, Ultimaker S5, Ultimaker S3 Ultimaker 2+ Connect.   
        They're ready for you on the Ultimaker Academy platform. All you need to do to gain access is to register your product to gain free access. 
        Ready? Register your product here in just 60 seconds.
          • Like
        • 14 replies
    • Create New...