Jump to content

Custom machine definition


V3DPrinting
Go to solution Solved by Slashee_the_Cow,

Recommended Posts

Posted (edited) · Custom machine definition

Dear community

 

I am currently making a custom machine definition and would like to return the material used in a specific extruder in my gcode

I have created a setting in my printer definition, children of blackmagic, using the extruder value extruderValue(extruder_nr,'material_type').

 

It returns the material used , but the problem is the value returned is a lowercase string and I need an uppercase string.

 

What would be the function to transform the string into uppercase ?

 

Thanks in advance

Edited by V3DPrinting
  • Link to post
    Share on other sites

    Posted · Custom machine definition

    @Slashee_the_Cow 

     

    Thanks for the feedback. I was a bit quick in my post.

    I am using the function extruderValue(0,'material_type') in the setting I have defined.

     

    The setting is the following

                    "used_material":

                    {

                        "comments": "V3DP setting",

                        "default_value": "",

                        "description": "Comment with the materials used.",

                        "enabled": false,

                        "label": "Used materials",

                        "settable_per_extruder": true,

                        "type": "str",

                        "value": "'T0 '+ extruderValue(0,'material_type') if print_mode == \"singleT0\" else 'T1 ' + extruderValue(1,'material_type') if print_mode == \"singleT1\"  else 'T0 ' + extruderValue(0,'material_type') + ' T1 ' + extruderValue(1,'material_type') if print_mode == \"dual\" else 'T0 ' + extruderValue(0,'material_type') + 'T1 ' + extruderValue(0,'material_type')"

                    },

     

    I know there is a replacement pattern for that, but it is not conditional, so I would like to have a dedicated setting. That would allow only one machine instance for all the print modes of my printer.

  • Link to post
    Share on other sites

    • Solution
    Posted · Custom machine definition
    1 hour ago, V3DPrinting said:

    "value": "'T0 '+ extruderValue(0,'material_type') if print_mode == \"singleT0\" else 'T1 ' + extruderValue(1,'material_type') if print_mode == \"singleT1\"  else 'T0 ' + extruderValue(0,'material_type') + ' T1 ' + extruderValue(1,'material_type') if print_mode == \"dual\" else 'T0 ' + extruderValue(0,'material_type') + 'T1 ' + extruderValue(0,'material_type')"

    Are you chaining three ternaries in a single line? Not cool (from a programming perspective). But... are you actually evaluating Python in that string? Not cool (from a programming perspective). But if you are... can't you just use string functions to make your string upper case?

    "value": "'T0 '+ extruderValue(0,'material_type').upper() if print_mode == \"singleT0\" else 'T1 ' + extruderValue(1,'material_type').upper() if print_mode == \"singleT1\"  else 'T0 ' + extruderValue(0,'material_type').upper() + ' T1 ' + extruderValue(1,'material_type').upper() if print_mode == \"dual\" else 'T0 ' + extruderValue(0,'material_type').upper() + 'T1 ' + extruderValue(0,'material_type').upper()"
  • Link to post
    Share on other sites

    Posted · Custom machine definition
    2 hours ago, Slashee_the_Cow said:

    Are you chaining three ternaries in a single line?

    Yes, because you cannot do block statements.

    2 hours ago, Slashee_the_Cow said:

    are you actually evaluating Python in that string

    Yes, and Cura specifically allows for that, and it is used throughout many printer definitions.

  • Link to post
    Share on other sites

    Posted · Custom machine definition

    @Slashee_the_Cow Thanks for the input works fine ! 

     

    I was looking for the string function, but I haven't found it in my googling. I need to improve my Python knowledge ....

     

    @ahoeben Thanks for your valuable help

  • Link to post
    Share on other sites

    Posted (edited) · Custom machine definition

    @ahoeben I wasn't trying to criticise or anything, just my (unique and easily misunderstood) style of wit, commenting that neither of them are cool if you're writing a program and have free reign, but I could tell that @V3DPrinting knew what they were doing (anyone who can keep track of what they're doing when nesting ternaries three deep isn't just a one trick pony who thinks they're the solution for everything) so was working within limitations.

     

    Although I didn't know you could use Python in machine definitions like that. You learn something new every day.

     

    Edit: I just realised that it doesn't help that I really hate the ternary syntax in Python. Don't get me wrong, it was a gift from above when they added it, but I'll take a C-style condition ? if_true : if_false over that every day of the week.

    Edited by Slashee_the_Cow
    Added comment about syntax
  • Link to post
    Share on other sites

    Posted (edited) · Custom machine definition
    22 hours ago, V3DPrinting said:

    would like to return the material used in a specific extruder in my gcode

    I have created a setting in my printer definition, children of blackmagic, using the extruder value extruderValue(extruder_nr,'material_type').

    It is unnecessary to abuse the settings system for that. Instead, just hook into the outputdevicemanager writestarted signal like eg the postprocessing plugin does (or another place where you can access the "gcode_dict" attribute of the scene). Settings should be used for things that users can put a value in, which affect printing.

     

        def __init__(self):
            super().__init__()
    
            self._application = Application.getInstance()
            output_manager = self._application.getOutputDeviceManager()
            output_manager.writeStarted.connect(self._filterGcode)
    
    
        def _filterGcode(self, output_device):
            scene = self._application.getController().getScene()
    
            gcode_dict = getattr(scene, "gcode_dict", {})
            if not gcode_dict: # this also checks for an empty dict
                Logger.log("w", "Scene has no gcode to process")
                return
    
            for plate_id in gcode_dict:
                gcode_list = gcode_dict[plate_id]
                if len(gcode_list) < 2:
                    Logger.log("w", "Plate %s does not contain any layers", plate_id)
                    continue
                    
                    
                    ... calculate/get used materials, insert them into gcode_list[0] ...
                    
            setattr(scene, "gcode_dict", gcode_dict)

     

    Edited by ahoeben
  • Link to post
    Share on other sites

    Posted · Custom machine definition

    @ahoeben Thanks for the piece of information. I'll have a look.

  • 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.7 stable released
        Cura 5.7 is here and it brings a handy new workflow improvement when using Thingiverse and Cura together, as well as additional capabilities for Method series printers, and a powerful way of sharing print settings using new printer-agnostic project files! Read on to find out about all of these improvements and more. 
         
          • Like
        • 20 replies
      • S-Line Firmware 8.3.0 was released Nov. 20th on the "Latest" firmware branch.
        (Sorry, was out of office when this released)

        This update is for...
        All UltiMaker S series  
        New features
         
        Temperature status. During print preparation, the temperatures of the print cores and build plate will be shown on the display. This gives a better indication of the progress and remaining wait time. Save log files in paused state. It is now possible to save the printer's log files to USB if the currently active print job is paused. Previously, the Dump logs to USB option was only enabled if the printer was in idle state. Confirm print removal via Digital Factory. If the printer is connected to the Digital Factory, it is now possible to confirm the removal of a previous print job via the Digital Factory interface. This is useful in situations where the build plate is clear, but the operator forgot to select Confirm removal on the printer’s display. Visit this page for more information about this feature.
          • Like
        • 0 replies
    ×
    ×
    • Create New...