Jump to content

How to make a plugin?


Go to solution Solved by ahoeben,

Recommended Posts

Posted · How to make a plugin?

I have been looking everywhere on how to make a plugin/script/whatever its called.

Whenever I refer to "plugin," I mean something like paintable supports or a theme change. Not post-processing.

 

I know python, and I'm on windows. So far, i have learned that you can add some folders and an __init__.py script into it in your appdata folder. I have gotten it to recognize that the plugin exists, but it says failed to load because nothing is in there. I also know that Cura itself is a bunch of plugins all working together to be one app, such as curaEngine, Uranium, etc. (Idk what these do btw, pls explain)

So, now that I know where to start, how can I begin to code the plugin? My plugin is supposed to create JSON files instead of .gcode for 3D printers in a little-known game called Scrap Mechanic. Look it up for further details. Point is, it needs to do this stuff with the goal of redoing the slicer for the game:
 

  • Voxelize the mesh into a bunch of cubes.
  • Generate support where necessary.
    • Support is much simpler in scrap, all I need is for every voxel that has nothing directly beneath it to have a block beneath it.
  • Display those cubes in the preview tab instead of traces of plastic. Support should be a different color of course.
    • If possible, add custom textures to the voxels
  • Save data in JSON (havent decided on format yet but thats easy)
  • Have its own tab/dropdown in settings, with a few settings:
    • Enabled - Whether or not it will use the custom slicer. If disabled, the whole plugin is a paperweight.
    • Voxel size - side length of each voxel in mm
    • Print type - A UUID for a specific block type in the game. (only used in final part in saving the json)
    • Support type - A different UUID for a support block to be used. (only used in final part in saving the json)


I don't imagine it to be too hard. I just need to know where documentation is and any other important stuff.

  • Link to post
    Share on other sites

    • Solution
    Posted · How to make a plugin?

    There is at least some documentation here:

    https://github.com/Ultimaker/Uranium/wiki/Plugins (and other pages in that wiki)

     

    Some example plugins can be found here:

    https://github.com/Ultimaker?q=uraniumexample&type=all&language=&sort=

     

    Often it is best to learn by example from the existing plugins, either the plugins that come with Cura, or the ones from the Marketplace. My own plugins aren't always necessarily "best practice" though.

     

    9 hours ago, Cogster said:

    I don't imagine it to be too hard.

    I think it is an ambitious set of features. Start small.

    • Like 2
    Link to post
    Share on other sites

    Posted · How to make a plugin?
    9 hours ago, Cogster said:

    I also know that Cura itself is a bunch of plugins all working together to be one app, such as curaEngine, Uranium, etc. (Idk what these do btw, pls explain)

    CuraEngine does the slicing and is an entirely separate process written in C++.

    Uranium is the framework Cura is built on and pretty much the whole Cura interface is made of Uranium plugins.

  • Link to post
    Share on other sites

    Posted · How to make a plugin?
    9 hours ago, Slashee_the_Cow said:

    CuraEngine does the slicing and is an entirely separate process written in C++.

    Uranium is the framework Cura is built on and pretty much the whole Cura interface is made of Uranium plugins.


    Ah so its impossible to rewrite the slicer? or no?

  • Link to post
    Share on other sites

    Posted · How to make a plugin?
    2 hours ago, Cogster said:

    Ah so its impossible to rewrite the slicer? or no?

     

    The source of the slicer (CuraEngine) is available, but it is written in C++ as @Slashee_the_Cow mentioned. You can make modifications to it and compile your own version. Or you can replace it altogether (but that would be even more "ambitious").

     

    The CuraEngine also has the concept of plugins, but they are a bit stricter in what can be done. CuraEngine plugins can be created in just about any language, because they are basically just small programs that runs alongside CuraEngine. Here's a minimal example written in Python:

    https://github.com/Ultimaker/CuraEngine_example_plugin_python

    There are versions of this example plugin in C++ and Rust too:

    https://github.com/Ultimaker/?q=curaengine_example_plugin&type=all&language=&sort=

     

    Finally, a more complete C++ CuraEngine plugin is available here:

    https://github.com/Ultimaker/CuraEngine_plugin_infill_generate

     

    I have no experience with writing CuraEngine plugins myself.

  • Link to post
    Share on other sites

    Posted · How to make a plugin?
    2 hours ago, GregValiant said:

    WHAT!!!  I'm crushed.  Should I have shamelessly stolen someone else's code?

    You should be shamelessly stealing my code for post-processing scripts. I mean more than at least one time I know of you already did.

     

    1 hour ago, ahoeben said:

    I have no experience with writing CuraEngine plugins myself.

    Does anyone? I'm not sure I've seen any other than the example tiled infill generator.

     

    3 hours ago, Cogster said:

    Ah so its impossible to rewrite the slicer? or no?

    As @ahoeben said: possible yes; practical no; plugin maaaaaaaybe. You wouldn't be the first person to bastardise CuraEngine into something it was never designed to be, but you'd probably be the first that isn't a Chinese printer manufacturer creating their own unnecessarily messed up fork of Cura.

  • Link to post
    Share on other sites

    Posted · How to make a plugin?
    16 minutes ago, Slashee_the_Cow said:

    You wouldn't be the first person to bastardise CuraEngine into something it was never designed to be, but you'd probably be the first that isn't a Chinese printer manufacturer creating their own unnecessarily messed up fork of Cura.


    But let's be honest, any software from China is... questionable to say the least. I will try to start by getting something to appear in settings and have curaEngine actually look at it, ie, if the custom slicer should be enabled.

    Also, would it be easier to do this in OrcaSlicer or similar? They don't have plugins but they seem to be easily modifiable. Would it be better to make my own entire slicer? I don't want to tackle rendering because thats really hard to do. I tried Unity but couldn't get custom GUI working.

  • Link to post
    Share on other sites

    Posted · How to make a plugin?
    8 hours ago, Cogster said:

    Would it be better to make my own entire slicer?

    Hard to tell, we don't know what you want to achieve with a slicer and that gamer.

     

    If you just want to output a JSON format instead of GCode, that could be done with a frontend-only Python plugin (which would transmogrify the layer data into the format you want). I think there's a uranium meshwriter example.

  • Link to post
    Share on other sites

    Posted · How to make a plugin?
    9 hours ago, ahoeben said:

    Hard to tell, we don't know what you want to achieve with a slicer and that gamer.

    ...
    i literally told you in the main post.
    maybe i wasnt clear, all i need is to redo the slicer to create voxels and save that in a custom format in a JSON file

    id imagine the first part is the hard one, json saving isnt too hard.

  • Link to post
    Share on other sites

    Posted · How to make a plugin?
    On 11/21/2024 at 3:54 AM, Cogster said:

    maybe i wasnt clear, all i need is to redo the slicer to create voxels

    That one: I won't say "impossible" but instead "practically impossible".

     

    I would create a front end plugin that uses existing Python libraries for working with meshes (don't reinvent the wheel) to voxelise it in that and then save the output JSON from your plugin, skipping the slicer entirely.

  • Link to post
    Share on other sites

    Posted · How to make a plugin?
    8 hours ago, Slashee_the_Cow said:

    I would create a front end plugin that ...

    But that would only convert the model, and would not create supports. That's what I meant with "we don't know what you want to achieve".

     

    Honestly I don't see why you would use Cura or another FDM slicer. Displaying a model really is not all that hard with the proper modules. Look into TrisMesh:

    https://pypi.org/project/trimesh/

    https://trimesh.org/

    It will handle loading models in various formats, has functionality to display them, and even has voxelizing capabilities built-in. And it has none of the complexity-you-don't-need from slicers.

     

    Incidentally, trimesh is included with Cura, and is what makes the Mesh Tools plugin do its thing.

  • Link to post
    Share on other sites

    Posted · How to make a plugin?
    1 hour ago, ahoeben said:

    But that would only convert the model, and would not create supports. That's what I meant with "we don't know what you want to achieve".

    As the OP said, support isn't hard, especially if you create it in voxels:

    On 11/19/2024 at 11:17 AM, Cogster said:

    Generate support where necessary.

    • Support is much simpler in scrap, all I need is for every voxel that has nothing directly beneath it to have a block beneath it.

     

  • 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.9 stable released!
        Here comes Cura 5.9 and in this stable release we have lots of material and printer profiles for UltiMaker printers, including the newly released Sketch Sprint. Additionally, scarf seams have been introduced alongside even more print settings and improvements.  Check out the rest of this article to find out the details on all of that and more
          • Like
        • 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
          • Heart
          • Thanks
          • Like
        • 4 replies
    ×
    ×
    • Create New...