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

      • 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
          • Like
        • 3 replies
      • 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. 
         
        • 26 replies
    ×
    ×
    • Create New...