Jump to content
UltiMaker Community of 3D Printing Experts

New mimetype: howto register it?


Daniel26

Recommended Posts

Posted (edited) · New mimetype: howto register it?

Hello,

 

I wrote a plugin which I wan't to start by a new mimetype. But how do I register that mimetype?

My __init__.py in the plugins directory:

def getMetaData():
    if "ChituCodeWriter.ChituCodeWriter" not in sys.modules:
        return {}

    return {
        "mesh_writer": {
            "output": [
                {
                    "mime_type": "text/chitu-g-code",
                    "mode": MeshWriter.OutputMode.TextMode,
                    "extension": "chitu",
                    "description": i18n_catalog.i18nc("@item:inlistbox", "chitu addons")
                }
            ]
        }
    }

Is that really enough so I can call that plugin via the printers definition with 

"file_formats": "text/x-gcode;text/chitu-g-code",

Regards

 

Daniel

Edited by Daniel26
  • Link to post
    Share on other sites

    Posted (edited) · New mimetype: howto register it?

    Sorry, here is the complete __init__.py

     

    import sys
    
    from UM.Logger import Logger
    try:
        from . import ChituCodeWriter
    except ImportError:
        Logger.log("w", "Could not import ChituCodeWriter")
    
    from UM.i18n import i18nCatalog #To translate the file format description.
    from UM.Mesh.MeshWriter import MeshWriter #For the binary mode flag.
    
    i18n_catalog = i18nCatalog("cura")
    
    def getMetaData():
        if "ChituCodeWriter.ChituCodeWriter" not in sys.modules:
            return {}
    
        return {
            "mesh_writer": {
                "output": [
                    {
                        "mime_type": "text/chitu-g-code",
                        "mode": MeshWriter.OutputMode.TextMode,
                        "extension": "chitu",
                        "description": i18n_catalog.i18nc("@item:inlistbox", "Chitu Code")
                    }
                ]
            }
        }
    
    def register(app):
        if "ChituCodeWriter.ChituCodeWriter" not in sys.modules:
            return {}
    
        return { "mesh_writer": ChituCodeWriter.ChituCodeWriter() }

     

     

    How can I be sure that the new mimetype is known by cura?

    I don't see any signs that my plugin is used.

     

    Regards

     

    Daniel

     

    Edited by Daniel26
  • Link to post
    Share on other sites

    Posted · New mimetype: howto register it?

    File -> Export should allow you to at least try to export as a .chitu file (Save as type). That is, unless ChituCodeWriter fails to import. If ChituCodeWriter fails to import, that should be visible in the logs.

     

     

  • Link to post
    Share on other sites

    Posted · New mimetype: howto register it?

    Ok. Thats for testing.

    What I wan't: if printer is a tronxy, the g-code should be created, that g-code hat to be modified by my plugin.

    How can I do that? Is that done by "file_formats": "text/x-gcode;text/chitu-g-code" in the printers definition?

     

    Sorry for that stupid questions, but I can't find any info about "Mesh_writer" Plugins.

     

    Regards

     

    Daniel

  • Link to post
    Share on other sites

    Posted · New mimetype: howto register it?

    > if printer is a tronxy, the g-code should be created, that g-code hat to be modified by my plugin.

     

    What sort of modifications are you talking about? Does the modified gcode file have to be named *.chitu? If not, it is easier/less confusing for the user to not use a meshwriter, but use something that simply post-processes the gcode when it is written.

  • Link to post
    Share on other sites

    Posted · New mimetype: howto register it?

    If you still want to go the MeshWriter route, I would suggest you take the GCodeGzWriter as an example/starting point:

    https://github.com/Ultimaker/Cura/tree/master/plugins/GCodeGzWriter

     

    https://github.com/Ultimaker/Cura/blob/master/plugins/GCodeGzWriter/GCodeGzWriter.py shows how to let the GCodeWriter to actually create the gcode file string, which you can then modify before you write it to the output stream.

  • Link to post
    Share on other sites

    Posted (edited) · New mimetype: howto register it?
    31 minutes ago, ahoeben said:

    > if printer is a tronxy, the g-code should be created, that g-code hat to be modified by my plugin.

     

    What sort of modifications are you talking about? Does the modified gcode file have to be named *.chitu? If not, it is easier/less confusing for the user to not use a meshwriter, but use something that simply post-processes the gcode when it is written.

     

    It adds e.g. a Screenshot to the gcode so the part is shown on the touchscreen of the printer. The timestamps also have a special format.

    I tried to submit a post process script, but they won't include it in the cura release. They advised me to write a mesh writer plugin and to submit it to the plugin database.

     

    Edited by Daniel26
  • Link to post
    Share on other sites

    Posted · New mimetype: howto register it?

    Ok, then have a look at the UFPWriter as an example instead.

  • Link to post
    Share on other sites

    Posted · New mimetype: howto register it?

    To Use the UFPWriter I have to "save as" and select "UFP"?

    If yes, this is not what I wan't.

    If I add a Tronxy printer the gcode simply has also "run thru" my plugin ans should be saved as gcode.

  • Link to post
    Share on other sites

    Posted · New mimetype: howto register it?
    49 minutes ago, Daniel26 said:

    To Use the UFPWriter I have to "save as" and select "UFP"?

    Yes, unless you specify your printer prefers using the mimetype specified in the UFPwriter plugin, like so:

     

    "file_formats": "application/x-ufp;text/x-gcode"

     

    Note how application/x-ufp is in front of text/x-gcode

  • Link to post
    Share on other sites

    Posted · New mimetype: howto register it?

    Do you want to write multiple files at once (ie: a thumbnail and a gcode file in two separate files)? That is not something the MeshWriter supports easily. You would have to build that yourself.

  • Link to post
    Share on other sites

    Posted · New mimetype: howto register it?
    Quote

    "file_formats": "application/x-ufp;text/x-gcode"

     

    Note how application/x-ufp is in front of text/x-gcode

     

    So, If I understand correctly: The file generated from ufp is "piped thru" the Script that creates the gcode? So with the order of the fileformats I can control the order the plugins are used?

     

    Quote

    Do you want to write multiple files at once (ie: a thumbnail and a gcode file in two separate files)? That is not something the MeshWriter supports easily. You would have to build that yourself.

    Nope. There are only additional M-Commands included in the gcode-file. So I only wan't one file.

     

  • Link to post
    Share on other sites

    Posted · New mimetype: howto register it?
    1 hour ago, Daniel26 said:

    If I understand correctly:

    No, that is not correct. There is no automatic piping of anything. The order of mimetypes just specifies what MeshWriter plugin is preferred for that printer. Only one MeshWriter gets called by Cura, but a MeshWriter might call other meshwriters.

     

    I'm sorry, I don't have time to hold your hand on this at the moment.

  • Link to post
    Share on other sites

    Posted · New mimetype: howto register it?

    No Prob, thanks. I will try to figure it out. Sadly, there is no documentation about that.

     

  • Link to post
    Share on other sites

    Posted · New mimetype: howto register it?

    Hmmm, my Plugin seems not to be registered. I put a simple "print" to the register and the getMetaData function, but I can't find the output in any log.

    Any idea?

  • Link to post
    Share on other sites

    Posted · New mimetype: howto register it?

    Not without either the full code you use (and where you put it) or a link to your cura.log

  • Link to post
    Share on other sites

    Posted · New mimetype: howto register it?

    Here the __init__.py:

    #Copyright (c) 2018 Ultimaker B.V.
    #Cura is released under the terms of the LGPLv3 or higher.
    
    import sys
    
    from UM.Logger import Logger
    try:
        from . import ChituCodeWriter
    except ImportError:
        Logger.log("w", "Could not import ChituCodeWriter")
    
    from UM.i18n import i18nCatalog #To translate the file format description.
    from UM.Mesh.MeshWriter import MeshWriter #For the binary mode flag.
    
    i18n_catalog = i18nCatalog("cura")
    
    def getMetaData():
        print("Loading chitu_mods metadata")
        if "ChituCodeWriter.ChituCodeWriter" not in sys.modules:
            return {}
    
        return {
            "mesh_writer": {
                "output": [
                    {
                        "mime_type": "text/chitu-g-code",
                        "mode": MeshWriter.OutputMode.TextMode,
                        "extension": "gcode",
                        "description": i18n_catalog.i18nc("@item:inlistbox", "Chitu gcode")
                    }
                ]
            }
        }
    
    def register(app):
        if "ChituCodeWriter.ChituCodeWriter" not in sys.modules:
            return {}
        else:
            print("fregistering chitu_mods")
            return { "mesh_writer": ChituCodeWriter.ChituCodeWriter() }

     

    Cura.log is attached.

     

    Thanks for your time

    cura.log

  • Link to post
    Share on other sites

    Posted · New mimetype: howto register it?

    Do you have a plugin.json? I don't think the plugin is loaded unless there is a plugin.json file with the appropriate data in it.

  • Link to post
    Share on other sites

    Posted · New mimetype: howto register it?
    {
        "name": "Chitu code Writer",
        "author": "Spanni26",
        "version": "1.0.0",
        "description": "Adds chitu code to gcode",
        "api": "7.1",
        "i18n-catalog": "cura"
    }

    Yes, see above.

     

  • Link to post
    Share on other sites

    Posted · New mimetype: howto register it?

    So, where did you put those files then?

     

    The print() in getMetaData() works for me. But since getMetaData() returns {} (because there is no ChituCodeWriter), register() never gets called.

     

    How do you run Cura? print() statements are not logged. They show up if you run Cura from source, but don't end up in cura.log. If you want entries in cura.log, use UM.Logger.Logger.log() instead.

  • Link to post
    Share on other sites

    Posted · New mimetype: howto register it?

    Ok, thanks. Will try the logger.

    The file are in a seprate folder in the plugins dir.

     

  • Link to post
    Share on other sites

    Posted · New mimetype: howto register it?

    Ok, tried it now with the logger, but still no message in the logs:

     

    #Copyright (c) 2018 Ultimaker B.V.
    #Cura is released under the terms of the LGPLv3 or higher.
    
    import sys
    
    from UM.Logger import Logger
    try:
        from . import ChituCodeWriter
    except ImportError:
        Logger.log("w", "Could not import ChituCodeWriter")
    
    from UM.i18n import i18nCatalog #To translate the file format description.
    from UM.Mesh.MeshWriter import MeshWriter #For the binary mode flag.
    
    i18n_catalog = i18nCatalog("cura")
    
    def getMetaData():
        Logger.log("w", "--- get metadata of ChituCodeWriter ---")
        if "ChituCodeWriter.ChituCodeWriter" not in sys.modules:
            return {}
    
        return {
            "mesh_writer": {
                "output": [
                    {
                        "mime_type": "text/chitu-g-code",
                        "mode": MeshWriter.OutputMode.TextMode,
                        "extension": "gcode",
                        "description": i18n_catalog.i18nc("@item:inlistbox", "Chitu gcode")
                    }
                ]
            }
        }
    
    def register(app):
        Logger.log("w", "--- register  ChituCodeWriter ---")
        if "ChituCodeWriter.ChituCodeWriter" not in sys.modules:
            return {}
        else:
            return { "mesh_writer": ChituCodeWriter.ChituCodeWriter() }

    Nothing in the logs.

    I also have no such mime type in the save-as-dialog.

     

    Frustrating...

     

    Regards


    Daniel

  • Link to post
    Share on other sites

    Posted · New mimetype: howto register it?

    It is also frustrating trying to help you when you don't answer simple questions.

  • Link to post
    Share on other sites

    Posted (edited) · New mimetype: howto register it?

    I start cura simply from windows with a double click on the icons.

    What else do you need? I will try to answer the questions.

    The source of the plugin is here: https://github.com/Spanni26/Cura/tree/master/plugins/ChituWriter

     

    Edited by Daniel26
  • 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

      • UltiMaker Cura 5.3 stable released
        In this stable release, Cura 5.3 achieves yet another huge leap forward in 3D printing thanks to material interlocking! As well as introducing an expanded recommended print settings menu and lots of print quality improvements. Not to mention, a whole bunch of new printer profiles for non-UltiMaker printers!
          • Thanks
        • 21 replies
      • 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
        • 18 replies
      • UltiMaker Cura 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
        • 22 replies
    ×
    ×
    • Create New...