Jump to content

Changing setting relations after a setting definition has been created


JJFX

Recommended Posts

Posted · Changing setting relations after a setting definition has been created

The plugin I'm developing adds a number of new settings to a new settings category. Some of them mirror other Cura settings by default and I'd like to change their relations once a user has modified a value.

 

For example, if the user defines a parent setting I'd like its children to now automatically follow the modified parent instead of their initial value function. Setting the value property seems to only accept defined values and I'm hitting a wall trying to get around this without needing to remaking setting definitions every time.

 

To clarify, here's a basic example of what I'd like to do...

 

## Following onExtruderSettingChanged function:
extruder_stack = self._application.getExtruderManager().getActiveExtruderStack()
is_user_value = extruder_stack.hasUserValue(setting)

if setting == "klipper_retraction_speed" and is_user_value:
  for child in ["klipper_retract_speed", "klipper_retract_prime_speed"]:
    extruder_stack.setProperty(child, 'value', "klipper_retraction_speed")

 

I'm currently using a crude workaround that detects the change, compares previous values then manually sets the children to the parent value but this isn't ideal and a bit buggy.

 

I suspect there's an obvious solution I'm overlooking but this one is getting the best of me :)

 

I'd greatly appreciate any insight, thanks!

 

JJ

 

 

  • Link to post
    Share on other sites

    Posted · Changing setting relations after a setting definition has been created

    You don't have to implement anything in Python; Cura already handles inheritance for you. Define the "value" of "klipper_retract_speed" as "klipper_retraction_speed". The "value" is a string that gets evaluated by Python, and all registered settings are available as variables in that string. You can also set the value to "klipper_rectraction_speed * 1.05" to have the value 5% higher than that of the "main" setting.

  • Link to post
    Share on other sites

    Posted · Changing setting relations after a setting definition has been created
    9 hours ago, ahoeben said:

    You don't have to implement anything in Python; Cura already handles inheritance for you. Define the "value" of "klipper_retract_speed" as "klipper_retraction_speed". The "value" is a string that gets evaluated by Python, and all registered settings are available as variables in that string. You can also set the value to "klipper_rectraction_speed * 1.05" to have the value 5% higher than that of the "main" setting.

     

    Thank you Aldo, I don't think my question was very clear. If I understand correctly, I believe you're referring to the initial setting definition. My issue is that I've already defined the inheritance for such settings. In this example, the initial values are defined by Cura's retraction settings but I'm trying to change the inheritance in Python after the user modifies a value as described above.

     

    "klipper_retraction_speed": {
      "label": "Retraction Speed",
      "description": "The speed in mm/s which...",
            "type": "float",
            "unit": "mm/s",
            "default_value": 0,
            "value": "retraction_speed",
            "minimum_value": "0",
            "minimum_value_warning": "5 if klipper_retract_speed >= 1 or klipper_retract_prime_speed >= 1 else 0",
            "maximum_value_warning": "99",
            "enabled": "resolveOrValue('machine_firmware_retract')",
            "settable_per_mesh": false, 
            "settable_per_extruder": true,
            "children": {
                "klipper_retract_speed": {
                    "label": "Retract Speed",
                    "description": "The speed at which...",
                    "type": "float",
                    "unit": "mm/s",
                    "default_value": 0,
                    "value": "retraction_retract_speed",
                    "minimum_value": "0",
                    "minimum_value_warning": "5 if klipper_retract_speed >= 1 else 0",
                    "maximum_value_warning": "99",
                    "enabled": "resolveOrValue('machine_firmware_retract')",
                    "settable_per_mesh": false, 
                    "settable_per_extruder": true
                },

     

    So my question is, is there way to easily adjust the value in Python so it's recognized as an expression or is this simply too unorthodox? If there is, there are a few other situations where I'd like to implement this as well.

     

    For reference, here is the repo for the plugin I'm working on.

     

    I truly appreciate the help!

  • Link to post
    Share on other sites

    Posted (edited) · Changing setting relations after a setting definition has been created
    7 hours ago, JJFX said:

    I'm trying to change the inheritance in Python after the user modifies a value as described above.

     

    I'm sorry, I still don't understand. Please provide a scenario, something like this:

     

    User enters value 'X' for setting 'Y'. 'Z' should happen. By just having the standard inheritance, 'A' happens instead. I could implement it by doing B, but then 'C' happens and that is undesirable because of 'D'

     

    It is better not to fight the Cura inheritance system, but work along with it.

    Edited by ahoeben
  • Link to post
    Share on other sites

    Posted · Changing setting relations after a setting definition has been created

    No problem, it is a bit convoluted. Basically I was trying to accomplish something like the 'value' of "klipper_retract_speed" below. Since this doesn't seem possible, I was looking for a way to do it after the fact in Python.

     

    "klipper_retraction_speed": {
        "label": "Retraction Speed",
        "description": "...",
        "type": "float",
        "unit": "mm/s",
        "default_value": 0,
        "value": "retraction_speed",
        "children": {
            "klipper_retract_speed": {
            "label": "Retract Speed",
            "description": "...",
            "type": "float",
            "unit": "mm/s",
            "default_value": 0,
            "value": "klipper_retraction_speed" if hasUserValue('klipper_retraction_speed') else "retraction_retract_speed",
        },

     

    Hopefully that makes sense.

     

    Admittedly, I'm realizing I should just take a break and reevaluate. It would make more sense to remove parent settings and simply avoid situations like this entirely. I'm curious if there is a way to do it but I think I'm making things unnecessarily complicated.

     

    Apologies for wasting your time.

  • 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

      • 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
      • Ultimaker Cura 5.6 stable released
        Cura now supports Method series printers!
         
        A year after the merger of Ultimaker and MakerBotQQ, we have unlocked the ability for users of our Method series printers to slice files using UltiMaker Cura. As of this release, users can find profiles for our Method and Method XL printers, as well as material profiles for ABS-R, ABS-CF, and RapidRinse. Meaning it’s now possible to use either Cura or the existing cloud-slicing software CloudPrint when printing with these printers or materials
        • 48 replies
    ×
    ×
    • Create New...