Jump to content

Query per-object settings for post-processing script development


Marco_Bre

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.8 beta released
        Another Cura release has arrived and in this 5.8 beta release, the focus is on improving Z seams, as well as completing support for the full Method series of printers by introducing a profile for the UltiMaker Method.
          • Like
        • 1 reply
      • 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
          • Thanks
          • Like
        • 3 replies
    ×
    ×
    • Create New...