Jump to content

Query per-object settings for post-processing script development


Recommended Posts

Posted (edited) · Query per-object settings for post-processing script development

Hello,

 

I am developing a post processing script that write the modified (and only those modified) print settings in the GCODE, like that:

# per object settings: True
; object_1 -> extruder_1
; object_2 -> extruder_1
; object_3 -> extruder_2
;
; Walls
;   Wall Thickness = 0.7
;     Wall Line Count = 4 (object_1)
;     Wall Line Count = 3 (extruder_1)          # not defined in object_2
;     Wall Line Count = 3 (object_3)
;   Wall Transition Length = 0.35 (extruder_1)  # do not duplicate this line for obj_1 & obj_2
;   Wall Transition Length = 0.35 (object_3)
;   Outer Wall Wipe Distance = 0.8
;   Outer Wall Inset = 0.04
;   Optimize Wall Printing Order = True
;   Minimum Wall Line Width = 0.34

# per object settings: False
; Walls
;   Wall Thickness = 0.7
;     Wall Line Count = 3 (extruder_1)
;   Wall Transition Length = 0.35 (extruder_1)
;   Wall Transition Length = 0.35 (extruder_2)
;   Outer Wall Wipe Distance = 0.8
;   Outer Wall Inset = 0.04
;   Optimize Wall Printing Order = True
;   Minimum Wall Line Width = 0.34

# show global and extruder override location: True
; Walls
;   Wall Thickness = 0.7 (global: quality_changes)
;     Wall Line Count = 3 (extruder_1: User)
;   Wall Transition Length = 0.35 (extruder_1: definition)
;   Wall Transition Length = 0.35 (extruder_2: material)
;   Outer Wall Wipe Distance = 0.8 (global: User)
;   Outer Wall Inset = 0.04 (global: User)
;   Optimize Wall Printing Order = True (global: User)
;   Minimum Wall Line Width = 0.34 (global: User)

 

However, I am currently very little aware of the capabilities of the cura API, and my script only gets the parameters from the extruder(s). When browsing the cura wiki (https://github.com/Ultimaker/Cura/wiki/Container-Stacks), I came across this picture:

image.thumb.png.a688ea89ecf4a8249d1c89a2d266099a.png

 

My new goal is to query all the object containers, and for each object, and each parameters, go down the stack to find the actual parameter value (the object parameter may not override every settings, and in fact, rarely do so).

 

My first question is:

How to query all the ContainerStack instances to access the per-Object settings? I did not find anything similar to `Application.getInstance().getGlobalContainerStack().extruderList` for objects.

 

The way I intend to write my script:

Because I want to know where a setting comes from, I can't let cura go down a stack, I have to do it myself.

- I will get the global definition to go through each and every settings in order

- for each setting

  - for each stack (from per-object, to global)

    - for each container (from Settings/User to definition)

      - I will check if a property exists.

        - if yes, I write it in the GCode with where it came from (I will have to be careful to not duplicate anything from extruder as multiple objects can inherit the same extruderstack)

        - if no, I will try the next container if it exists, or the next stack

 

Do you have any remarks on how I could approach this problem better ?

 

Thank you in advance.

image.png

Edited by Marco_Bre
Better script example
  • Link to post
    Share on other sites

    Posted (edited) · Query per-object settings for post-processing script development

    You might also want to check the godmode plugin, which already does some of the things that you're asking for (https://github.com/sedwards2009/cura-god-mode-plugin)

    Walking over all stacks and figuring if they have an actual value set is done (although with more logic than you would need) in the SettingInheritanceManager: https://github.com/Ultimaker/Cura/blob/f130eb2e7cafdec78849d5763f2914d609691718/cura/Settings/SettingInheritanceManager.py#L171

    So basicly, you can get all the keys of a profile by using getAllKeys().

    So you would need to do something like:

    for container in stack:
    	for setting_key in container.getAllKeys():
    		print(f"{container.getName()}: {setting_key}: {container.getProperty(setting_key, 'value')}")


    I didn't actually check that code, so you might need to change some things to get that to work.

    If you want to know if an object has per object settings, you wil need to check it's decorator. So you will need to loop over all objects in the scene and check if they have any settings in their per object stack. There isn't a global function to get all of them (as we only do this in the CuraEngine plugin and it's never re-used anywhere else)

    Edited by nallath
    • Heart 1
    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
        • 56 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
        • 34 replies
    ×
    ×
    • Create New...