Jump to content
UltiMaker Community of 3D Printing Experts

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

      • UltiMaker Cura 5.3 stable released
        In this stable release, Cura 5.3 achieves yet another huge leap forward in 3D printing thanks to material interlocking! As well as introducing an expanded recommended print settings menu and lots of print quality improvements. Not to mention, a whole bunch of new printer profiles for non-UltiMaker printers!
          • Thanks
          • Like
        • 28 replies
      • Here it is. The new UltiMaker S7
        The UltiMaker S7 is built on the success of the UltiMaker S5 and its design decisions were heavily based on feedback from customers.
         
         
        So what’s new?
        The obvious change is the S7’s height. It now includes an integrated Air Manager. This filters the exhaust air of every print and also improves build temperature stability. To further enclose the build chamber the S7 only has one magnetically latched door.
         
        The build stack has also been completely redesigned. A PEI-coated flexible steel build plate makes a big difference to productivity. Not only do you not need tools to pop a printed part off. But we also don’t recommend using or adhesion structures for UltiMaker materials (except PC, because...it’s PC). Along with that, 4 pins and 25 magnets make it easy to replace the flex plate perfectly – even with one hand.
         
        The re-engineered print head has an inductive sensor which reduces noise when probing the build plate. This effectively makes it much harder to not achieve a perfect first layer, improving overall print success. We also reversed the front fan direction (fewer plastic hairs, less maintenance), made the print core door magnets stronger, and add a sensor that helps avoid flooding.
         

         
        The UltiMaker S7 also includes quality of life improvements:
        Reliable bed tilt compensation (no more thumbscrews) 2.4 and 5 GHz Wi-Fi A 1080p camera (mounted higher for a better view) Compatibility with 280+ Marketplace materials Compatibility with S5 project files (no reslicing needed) And a whole lot more  
        Curious to see the S7 in action?
        We’re hosting a free tech demo on February 7.
        It will be live and you can ask any questions to our CTO, Miguel Calvo.
        Register here for the Webinar
          • Like
        • 18 replies
      • UltiMaker Cura Alpha 🎄 Tree Support Spotlight 🎄
        Are you a fan of tree support, but dislike the removal process and the amount of filament it uses? Then we would like to invite you to try this special release of UltiMaker Cura. Brought to you by our special community contributor @thomasrahm
         
        We generated a special version of Cura 5.2 called 5.3.0 Alpha + Xmas. The only changes we introduced compared to UltiMaker Cura 5.2.1 are those which are needed for the new supports. So keep in mind, this is not a sneak peek for Cura 5.3 (there are some really cool new features coming up) but a spotlight release highlighting this new version of tree supports.  
          • Like
        • 22 replies
    ×
    ×
    • Create New...