Jump to content

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.8 Stable released 🎉
        In the Cura 5.8 stable release, everyone can now tune their Z seams to look better than ever. Method series users get access to new material profiles, and the base Method model now has a printer profile, meaning the whole Method series is now supported in Cura!
        • 5 replies
      • Introducing the UltiMaker Factor 4
        We are happy to announce the next evolution in the UltiMaker 3D printer lineup: the UltiMaker Factor 4 industrial-grade 3D printer, designed to take manufacturing to new levels of efficiency and reliability. Factor 4 is an end-to-end 3D printing solution for light industrial applications
          • Thanks
          • Like
        • 3 replies
    ×
    ×
    • Create New...