Unwrapping Script for Pixel Art texturing

I’m trying to create a script to prep models for pixel art texture painting and I’m having a hard time finding the operations to use. I am also quite new to python scriptting.

I’m using a strict grid snap so my models are low poly and each grid will equate to 1 pixel of texture. The operations in trying to perform for the unwrap are as follows:

  1. get the bounding box and normal of each face of the model.
  2. find the axis of the normal that is closest to 1.
  3. scale that axis to zero on the bounds.
  4. scale to resulting plane by the texture size (4096x4096) and pixel scale (32px/unit) that I’m using for that model
  5. set the vertex corner position to UV space.

I’m not to concerned about island packing as I will be doing that manually, the texture will have multiple models baked into it that are from separate blend files. This script is to speed up the pipeline for getting the models to a pixel perfect unwrap. Any help is greatly appreciated.

Here is an example of 1 of the models I have unwrapped before but, I need to bring it into the combined 4k texture I want all my models to be using.