Automatic Layer Height Optimizer [script]
 
Notifications
Clear all

Automatic Layer Height Optimizer [script]  

  RSS
3D Printing Pro
(@3d-printing-pro)
Active Member
Automatic Layer Height Optimizer [script]

Reporting my post AND SCRIPT from PrusaSlicer github just to allow more users to get the script

It's quite annoying to be forced to design objects with the flat surfaces height based on the layer height at which they will be printed

(e.g. slicing a 10,1 mm high cube with 0,20 mm layer height leads to a 10.2 mm high cube)

So, i suggest a smart modification of the layer height based on the distance of flat surfaces from the heated bed, exploiting the layer editing feature to make it automatic,

(for instance, slicing a 10,1 mm high cube at "smart" 0.20 mm layer height could lead to 41 layers 0.20 mm thick + 10 layers 0.19 mm thick --> 10.1 mm high cube)

Here it is!

Python3 script which optimizes the layerheight in order to match right z values on flat surfaces (as per 1st post), approximated at 0.01 mm
[layer height only supported in in PrusaSlicer2.1.0-alpha1 for the moment]

usage:
python3 LH-optimizer.py <default_layer_height_in_mm> <file.stl>
example:
python3 LH-optimizer.py 0.40 mystlfule.stl

output:

 0.0  -->  0.2  -  0.2
 0.2  -->  0.9  -  0.35
 0.9  -->  3.0  -  0.42
 3.0  -->  5.0  -  0.4
 5.0  -->  11.24  -  0.39

 

Attachment removed
This topic was modified 2 years ago 3 times by 3D Printing Pro
...
Posted : 23/08/2019 6:51 pm
--
 --
(@)
Illustrious Member
RE: Automatic Layer Height Optimizer [script]

What does it do to a slope?

Posted : 23/08/2019 7:54 pm
bobstro
(@bobstro)
Illustrious Member
RE: Automatic Layer Height Optimizer [script]

So this spits out optimal layer heights based on the STL? Do these have to be manually entered?

I know the post-fork branch of Slic3r has enabled automatic dynamic layer heights.

My notes and disclaimers on 3D printing and miscellaneous other tech projects
He is intelligent, but not experienced. His pattern indicates two dimensional thinking. -- Spock in Star Trek: The Wrath of Khan...
Posted : 23/08/2019 8:15 pm
3D Printing Pro
(@3d-printing-pro)
Active Member
Topic starter answered:
RE: Automatic Layer Height Optimizer [script]
Posted by: Tim

What does it do to a slope?

Slopes are ignired, i just optimize horizontal surfaces for mechanical precision

...
Posted : 23/08/2019 8:34 pm
bobstro
(@bobstro)
Illustrious Member
RE: Automatic Layer Height Optimizer [script]

Adjusting the layer height of a part just to make it an integer multiplier for layers to a flat surface height sounds like it might require quite a bit of printing at sub-optimal smaller heights, significantly increasing print time.If my top layer is an even multiple of layer height, how is it more precise? I can understand concerns about stepper accuracy, but your approach doesn't seem to take that into account. What mechanical difference does this accomplish? 

My notes and disclaimers on 3D printing and miscellaneous other tech projects
He is intelligent, but not experienced. His pattern indicates two dimensional thinking. -- Spock in Star Trek: The Wrath of Khan...
Posted : 23/08/2019 8:43 pm
3D Printing Pro
(@3d-printing-pro)
Active Member
Topic starter answered:
RE: Automatic Layer Height Optimizer [script]
Posted by: bobstro

So this spits out optimal layer heights based on the STL? Do these have to be manually entered?

I know the post-fork branch of Slic3r has enabled automatic dynamic layer heights.

yes on STL, and yes, manually (but it also acreate a file which can be used in the .3mf file if you save it from PrusaSlicer

I didn't know it, I hope they will port it to PrusaSlicer too

 

...
Posted : 23/08/2019 8:44 pm
3D Printing Pro
(@3d-printing-pro)
Active Member
Topic starter answered:
RE: Automatic Layer Height Optimizer [script]
Posted by: bobstro

Adjusting the layer height of a part just to make it an integer multiplier for layers to a flat surface height sounds like it might require quite a bit of printing at sub-optimal smaller heights, significantly increasing print time.If my top layer is an even multiple of layer height, how is it more precise? I can understand concerns about stepper accuracy, but your approach doesn't seem to take that into account. What mechanical difference does this accomplish? 

The point is to be accurate even when you can't model with multiple of the layer height (let's say you need a part 1.9 mm thick)

If you have a part 1.9 mm thick usually the slicer does not treat it correctly, giving you a 2mm thick part if you use 0.20 mm layers.

Having layers 1 cent less (0.19 mm instead of 0.20 mm) does not make the print much longer but allows odd thickness to be printed correctly.

Try slicing this stairway.stl with standard settings

 

 

This post was modified 2 years ago by 3D Printing Pro
...
Posted : 23/08/2019 8:50 pm
3D Printing Pro
(@3d-printing-pro)
Active Member
Topic starter answered:
RE: Automatic Layer Height Optimizer [script]

STL for testing uploded to PrusaPrinters: Stairway.stl

...
Posted : 23/08/2019 8:59 pm
--
 --
(@)
Illustrious Member
RE: Automatic Layer Height Optimizer [script]

Does the script also properly adjust extrusion rates?  

 

ps: rather than directing people to weird third party web sites where security is unknown: zip the file and post inline here on the forum.

This post was modified 2 years ago by --
Posted : 23/08/2019 9:59 pm
3D Printing Pro
(@3d-printing-pro)
Active Member
Topic starter answered:
RE: Automatic Layer Height Optimizer [script]

Why the extrusion rate?

If you use the value given by the script in the PrusaSlicer layer height function (re-introduced in 2.1.0-alpha1) the software adjust it automatically.

 

...
Posted : 23/08/2019 10:15 pm
--
 --
(@)
Illustrious Member
RE: Automatic Layer Height Optimizer [script]

Sorry - the formats you are posting are incompatible with all of my editors, including Idle 3.7 ... as for extrusion rates; I thought your script was modifying gcode, not somehow trying to integrate into Slicer.

And I'm not getting the reason for editing only some of the layers to gain a certain height.  Seems like for all the work (and risk) or using such a script is much more effort than simply doing the math to plan for a set layer tolerance in the first place. My cube needs to be 19.88 mm tall, I want about 0.2 mm layers, about 99 layers, so I change layer heights to 0.2008.  Or if I use 100 layers, then layer height is 0.1988.  Problem solved.

This post was modified 2 years ago by --
Posted : 24/08/2019 12:36 am
3D Printing Pro
(@3d-printing-pro)
Active Member
Topic starter answered:
RE: Automatic Layer Height Optimizer [script]
Posted by: Tim

Sorry - the formats you are posting are incompatible with all of my editors, including Idle 3.7 ... as for extrusion rates; I thought your script was modifying gcode, not somehow trying to integrate into Slicer.

And I'm not getting the reason for editing only some of the layers to gain a certain height.  Seems like for all the work (and risk) or using such a script is much more effort than simply doing the math to plan for a set layer tolerance in the first place. My cube needs to be 19.88 mm tall, I want about 0.2 mm layers, about 99 layers, so I change layer heights to 0.2008.  Or if I use 100 layers, then layer height is 0.1988.  Problem solved.

About the file: Strange... please find the attached zip file with Script + STL + FreeCAD file of the staircase

About the cube: well, if we would be printing cubes only it would be ok to set a fixed layer height, but usually I print much more complicated parts...

The attached staircase for example, how could it be printed correctly with constant layer height?

If you want layers about 0.20 mm thick, this is the best way to set them (best in the sense that you have the minimal deviation from the selected layer height)

python3 LH-optimizer-2.py 0.20 stairway.stl 
--------------------------------------------------------
Optimal Layer Height calculator with 0.01 mm approximation, parameters used:
First Layer Height: 0.2 mm (will not be changed)
Default Layer Height: 0.2 mm
Z-Steps and Height Approximation: 0.01 mm
........................................................
0.0 --> 0.2 - 0.2
0.2 --> 0.54 - 0.17
0.54 --> 0.9 - 0.18
0.9 --> 3.0 - 0.21
3.0 --> 5.0 - 0.2
5.0 --> 5.95 - 0.19
5.95 --> 9.35 - 0.2
9.35 --> 11.24 - 0.21
Attachment removed
...
Posted : 24/08/2019 7:11 am
--
 --
(@)
Illustrious Member
RE: Automatic Layer Height Optimizer [script]

I seriously doubt the MK3 can be accurate within 0.05 mm regardless, especially because layer 1 is variable due to hardware limitations (mesh level compensates +/-0.1 mm and you have no control over that), so 0.1 mm layers would do fine for your stair case.   And seriously, is 0.002 (0.05 mm) inches even a consideration for FDM printing?  My printer flexes that much if I push on the control knob to make an adjustment. 

You should take a look at that variable Z thread; it's already implemented for Slicer, and can do actual variable contours. No layer steps on the surface ... pretty impressive, and would handle your part fairly well. 

 

Posted : 24/08/2019 7:47 am
3D Printing Pro
(@3d-printing-pro)
Active Member
Topic starter answered:
RE: Automatic Layer Height Optimizer [script]
Posted by: Tim

I seriously doubt the MK3 can be accurate within 0.05 mm regardless, especially because layer 1 is variable due to hardware limitations (mesh level compensates +/-0.1 mm and you have no control over that), so 0.1 mm layers would do fine for your stair case.   And seriously, is 0.002 (0.05 mm) inches even a consideration for FDM printing?  My printer flexes that much if I push on the control knob to make an adjustment. 

You should take a look at that variable Z thread; it's already implemented for Slicer, and can do actual variable contours. No layer steps on the surface ... pretty impressive, and would handle your part fairly well. 

 

I know that 3d printers cannot achieve 0.01 mm accuracy, but if you sum a slicing error (which could be prevented) to the mechanical error (which cannot be avoided), things does not get better.

If you talk about the Smooth Layer Editing feature, I know it, and find it good for curved / sloped surfaces, but at the moment it's not like the Layer Editing tables for flat surfaces (that's why several people complained when they removed it in PrusaSlicer-2.0)

 

...
Posted : 24/08/2019 8:12 am
3D Printing Pro
(@3d-printing-pro)
Active Member
Topic starter answered:
RE: Automatic Layer Height Optimizer [script]

One more consideration:

This script become more useful when you increase the layer height beyond the Prusa default 0.20 mm

If you print at 0.05 mm layer height, this script might not be so useful, but if you print at 0.4 mm or more (as I do) you really don't want 0.20+ mm of slicing error in your parts...

...
Posted : 24/08/2019 8:29 am
jakori.tahari
(@jakori-tahari)
New Member
RE: Automatic Layer Height Optimizer [script]

I'm not getting the reason for editing only some of the layers to gain a certain height.  Seems like for all the work (and risk) or using such a script is much more effort than simply doing the math to plan for a set layer tolerance in the first place. 

Posted : 14/09/2019 2:40 pm
KevinK
(@kevink)
Trusted Member
RE: Automatic Layer Height Optimizer [script]

I actually think this is a real need and that the slicer should do this automatically.  As things stand with .2 layers you are always subject to a .1 error potential.  While I don't normally have the need for the external lines to be as accurate as possible, I have definitely seen this issue with "clearances" where one part needs to fit into another.  There you may be shooting for a .1mm total vertical clearance, and because there is a top and bottom surface not be able to get anywhere near that.  This tool wouldn't help my case which is while I applaud the effort and will remember it for any case where it would help me, what I really want is for the slicer to correctly honor all boundary dimensions to the accuracy possible.  Thus on any external horizontal surface, the slicer ought to strive to print that surface (or bridge bottom) at the correct distance from the reference plane (the print bed).  If this means adjusting layer heights approaching that surface then it should do that as smoothly as possible.  I'd be fine if this were an advanced feature that was controlled by a boolean but it really should work correctly.  For those of us who mostly print functional parts it would definitely be a help.  (I consider this in the same class as thin fills for vertical surfaces only for the horizontal case.)

Posted : 14/09/2019 4:05 pm
3D Printing Pro
(@3d-printing-pro)
Active Member
Topic starter answered:
RE: Automatic Layer Height Optimizer [script]

New version of the script, with some improvements:

  • Works directly with .3mf files instead of .stl (models can be oriented and scaled before optimization)
  • Saves the layers directly in a new .3mf file named OPTLH_old.file_name.3mf
  • Optional Parameter: max_layer_height (usually you want to set it at 0.75*nozzle-width)
Usage:  NEW-LH-optimizer.py <file.3mf> <default_layer_height_in_mm> [max_layer_height_in_mm]
Attachment removed
...
Posted : 16/07/2020 7:19 pm
bobstro
(@bobstro)
Illustrious Member
RE: Automatic Layer Height Optimizer [script]

A lot has happened since we discussed this last. PrusaSlicer has been updated with an automatic variable layer height feature that will adjust individual layer heights to preserve detail. Here's an example:

In the bar at right, highlighted in orange, shows different colors for each layer height, from 0.4 to 0.08mm. This feature has made a big difference on top layer quality in my tests.

 

 

 

My notes and disclaimers on 3D printing and miscellaneous other tech projects
He is intelligent, but not experienced. His pattern indicates two dimensional thinking. -- Spock in Star Trek: The Wrath of Khan...
Posted : 16/07/2020 7:54 pm
Share: