Jump to content

If statement in Postprocessing, Layer height


taconite

Recommended Posts

Posted · If statement in Postprocessing, Layer height

Good evening fellow 3D-printing enthusiasts,

 

I am new to this forum and have a problem - I couldn't find a topic with the search function. I have no idea if this is the correct forum for my inquiry - maybe a moderator could help me out.

I would like to add some code to the g-code with postprocessing. I would like to add different code dependent on the layer height like:

 

if(layer height==0.3)

{

// some g-code

}

elseif(layer height == 0.1)

{

// some other g-code

}

else

{

// default g-code

}

 

is this possible with the post-processing plug-in (I will use the search and replace function)?

what is the variable for the layer height? layer_height ... ?

 

I am using Cura 3.4

 

Thank you for your help

 

Best Regards

 

 

  • Like 1
Link to post
Share on other sites

Posted · If statement in Postprocessing, Layer height

Read about post processing plugins.  There are bout 6 of them that come with cura.  Look at the code in them.  They use python.  Python is a general purpose language so you can do anything in a post processing script that you can do in any language.

 

Maybe start by looking at the names of the scripts (go to extensions, post-processing, modify g-code, then click add-a-script.  Try to find the python files that go with those script names using grep.  They'll be in the same folder tree structure as cura.

  • Link to post
    Share on other sites

    Posted · If statement in Postprocessing, Layer height

    Thank you for your reply

     

    I already did that but couldn't find a switch-case style or if-statement but anyhow because it is just python I will figure it out (I hope so).

     

    But does anyone know how the variable for the layer height is called?

  • Link to post
    Share on other sites

    Posted · If statement in Postprocessing, Layer height

    What do you mean by "variable"? A python variable? There is not global python variable for the layer height in Cura.

     

    There is a setting called "layer_height". To get its value, you would call the method getPropertyValue on the "global stack".

     

    global_stack = Application.getInstance().getGlobalContainerStack()
    layer_height = global_stack.getProperty("layer_height", "value")

     

    • Like 2
    Link to post
    Share on other sites

    Posted · If statement in Postprocessing, Layer height
    16 hours ago, ahoeben said:

    What do you mean by "variable"? A python variable? There is not global python variable for the layer height in Cura.

     

    There is a setting called "layer_height". To get its value, you would call the method getPropertyValue on the "global stack".

     

    
    global_stack = Application.getInstance().getGlobalContainerStack()
    layer_height = global_stack.getProperty("layer_height", "value")

     

     

     

    Thanks, I could definitely use that at some point!

    What would the spelling look like for "material_standby_temperature"?

    Global_stack.getProperty (material_standby_temperature, value) returns only the default value of fdmprinter.def.json.

    It would be best if extruders were also possible dependent!

  • Link to post
    Share on other sites

    Posted · If statement in Postprocessing, Layer height
    26 minutes ago, zerspaner_gerd said:

    Global_stack.getProperty (material_standby_temperature, value) returns only the default value of fdmprinter.def.json.

     

    That is because material_standby_temperature is set per extruder, so instead of the global stack you need to look at one of the extruder stacks.

     

    For example, this gets the standby temperature set for the first extruder:

    first_extruder_stack = ExtruderManager.getInstance().getActiveExtruderStacks()[0]
    material_standby_temperature = first_extruder_stack.getProperty("material_standby_temperature", "value")

     

    • Like 2
    Link to post
    Share on other sites

    Posted · If statement in Postprocessing, Layer height

    Excuse me @ahoeben ?,

     

    has changed a bit with Cura 3.5.1, it does not work anymore.

    t0_extruder_stack = ExtruderManager.getInstance().getActiveExtruderStacks()[0]


    The post processing plugin is not displayed at all, if I hide it it will appear again for selection.

     

    I tried a lot, without success. I do not know where to read up something.

  • Link to post
    Share on other sites

    Posted · If statement in Postprocessing, Layer height

    Check cura.log in Help -> Show configuration folder. Search for the id (filename without .py) of your script, and it should give you a hint about why it is not loading. If not, I'm going to have to see the entire script.

  • Link to post
    Share on other sites

    Posted · If statement in Postprocessing, Layer height
    2018-10-25 23:29:12,563 - ERROR - [MainThread] UM.Logger.logException [84]: Exception: Exception occurred while loading post processing plugin: list index out of range
    2018-10-25 23:29:12,565 - ERROR - [MainThread] UM.Logger.logException [88]: Traceback (most recent call last):
    2018-10-25 23:29:12,566 - ERROR - [MainThread] UM.Logger.logException [88]:   File "C:\Program Files\Ultimaker Cura 3.5\plugins\PostProcessingPlugin\PostProcessingPlugin.py", line 155, in loadScripts
    2018-10-25 23:29:12,567 - ERROR - [MainThread] UM.Logger.logException [88]:     temp_object = loaded_class()
    2018-10-25 23:29:12,568 - ERROR - [MainThread] UM.Logger.logException [88]:   File "C:\Program Files\Ultimaker Cura 3.5\plugins\PostProcessingPlugin\scripts\test2_settings_cura.py", line 22, in __init__
    2018-10-25 23:29:12,569 - ERROR - [MainThread] UM.Logger.logException [88]:     self.t0_extruder_stack = ExtruderManager.getInstance().getActiveExtruderStacks()[0]
    2018-10-25 23:29:12,570 - ERROR - [MainThread] UM.Logger.logException [88]: IndexError: list index out of range

    It had worked with Cura 3.4.
    Have now changed the order, now it seems to work again!


    That was my previous one sequence:

    from ..Script import Script
    from UM.Application import Application
    from cura.Settings.ExtruderManager import ExtruderManager
    import re
    
    class test2_settings_cura(Script):
        version = "1.0.0"
        def __init__(self):
            super().__init__()
            ########################################################################################################################
            self.global_stack = Application.getInstance().getGlobalContainerStack()
            self.t0_extruder_stack = ExtruderManager.getInstance().getActiveExtruderStacks()[0]
            self.t1_extruder_stack = ExtruderManager.getInstance().getActiveExtruderStacks()[1]
            ########################################################################################################################
    
        def getSettingDataString(self):
            return """{
                "name":"Test Settings Cura """ + self.version + """",
                "key": "test2_settings_cura",
                "metadata": {},
                "version": 2,
                "settings":
                {
    
                }
            }"""
    
        def execute(self, data):
            layers_started = False
    
            ########################################################################################################################
    
    
            layer_height = self.global_stack.getProperty("layer_height", "value")
            Turm = self.global_stack.getProperty("prime_tower_position_x", "value")
            flover = self.global_stack.getProperty("machine_gcode_flavor", "value")
    
    
            material_standby_temperature_T0 = self.t0_extruder_stack.getProperty("material_standby_temperature", "value")
            material_standby_temperature_T1 = self.t1_extruder_stack.getProperty("material_standby_temperature", "value")
    
    
            ########################################################################################################################
    
    
            for layer in data:
                modified_layer = ""
    
                index = data.index(layer)
                lines = layer.split("\n")
                for line in lines:
    
                    if ";Generated with Cura_SteamEngine " in line:
                        modified_layer += ";With Dual Script RepRap Duet3D V%s\n" % self.version + line +"\n\n"
    
                        modified_layer += ";TES TESTE Layer:%f\n\n" % layer_height
                        modified_layer += ";TES TESTE tover pos.x:%f\n\n" % Turm
                        modified_layer += ";TES TESTE flover:%s\n\n" % flover
                        modified_layer += ";TES TESTE Standby_T0:%s\n\n" % material_standby_temperature_T0
                        modified_layer += ";TES TESTE Standby_T1:%s\n\n" % material_standby_temperature_T1
    
                        layers_started = True
                        continue
    
                    if not layers_started:
                        #insert original line
                        modified_layer += line + "\n"
                        continue
    
    
                    else:
                        #insert original line
                        if line == "":
                            modified_layer += line
                        else:
                            modified_layer += line + "\n"
    
                #replace the layer with the modified data
                data[index] = modified_layer
            return data

     

    No matter you, now it works again
    Thanks

  • Link to post
    Share on other sites

    Posted · If statement in Postprocessing, Layer height

    Without looking too much into the rest of the code, you are looking up the stacks in the __init__ method. That method gets called when the PostProcessing script discovers the available scripts, which might be before Cura has finished loading the printers from your configuration. Even if it worked, the information would also be incorrect once you changed to another printer in Cura.

     

    Don't do postprocessing things in __init__, but do them in execute.

    • Like 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

      • 🎄✨ Thingiverse Tree Ornament Challenge! ✨🎄
        We've been running a Tree Ornament Challenge with a chance to win an UltiMaker S3 or colorFabb filament.
        Design a 3D printable tree ornament and join our festive challenge on Thingiverse. 🎁✨


        📆 Submission Deadline: December 22
        🏷️Tag your designs with Holidays2023

        Click here to join and check out the over 300 other amazing designs

        How to Enter
        Design an Ornament
        Create a 3D printable tree ornament that captures the magic of the winter season. Think snowflakes, sleighs, reindeer, cozy mittens, or anything that embodies the joy of the holidays. Upload to Thingiverse
        Share your masterpiece on Thingiverse and add the tag Holidays2023. Don't forget to include a captivating description and images that showcase your design from different angles. Submit by December 22
        All entries must be submitted by December 22nd to be eligible for consideration.
          Entering a new design
         
        Entering an existing design
         
         
        Winning designs should:
        Be original Creations
        Your designs should be original works, avoiding the use of others' intellectual property without permission. Include STL Files
        Each submission must include at least one STL file for 3D printing. Showcase a Completed Print
        Provide at least one photograph featuring a completed print of your design. Include Documentation
        Share the creative journey! Include documentation of your design process, giving us a peek behind the scenes. For example, show a screenshot of the model in your design program. Use the Tag Holidays2023.
        Use this tag to ensure your entry is counted in the Tree Ornament Challenge. Be submitted after October 1st, 2023
        Ensure your design was uploaded to Thingiverse after October 1st, 2023. Adhere to Submission Guidelines and Terms of Service
        Make sure your submission aligns with our guidelines and Thingiverse's Terms of Service.  
        Good luck 🎉
        • 1 reply
      • 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
        • 14 replies
    ×
    ×
    • Create New...