Scripting Creation of Book Models and their Texture Mapping

I am trying to write a script that makes texture mapping and creating books faster.

What I have so far is a script that:

  • makes me ‘draw’ a PictureFrame with a book’s cover (the size is used for the model created)
  • makes me specify two points on the PictureFrame to calculate the width of the book’s back.
  • creates a (for now) very simple model that looks like a box and has two parts: cover and pages.

Then I need to manually always do the same:

  • Select the cover
  • ‘Unwrap’ it without choosing seams
  • open UV Editor
  • draw a rectangle exactly on top of the PictureFrame’s edge
  • rotate the mesh 90° CCW
  • move bottom left of mesh to bottom left of PictureFrame
  • Scale1d to top left point of PictureFrame
  • Scale1d to bottom right point of PictureFrame
  • click apply

Then, when the PictureFrame is applied as material, the cover looks good.

That is a lot faster than before, but can the manual unwrapping part perhaps be scripted, too? I mean, even if ‘Unwrap’ is not accessible using RC, the final mesh always has 8 vertices (on the PictureFrame’s edge), 6 triangles, and the PictureFrame’s size. So, I just need to make the object believe it was unwrapped and pass it a mesh?! Is that possible? (923.0 KB)