Hi, interesting project. I have a friend who worked on a similar task (using stock of defined lengths to fill other length) before, he made a few c# scripts for that. I can share his definition if you dm me.
Also there was an old topic for that, check this out: