Automated Texture Exports

I've got far enough in Python to start taking apart other people's scripts and reassembling them to do the things I want them to do. Towards this end I have taken the Photoshop layer exporter script by Adam Pletcher and modified it in several key ways to adapt it to the pipeline I'm currently working in.

I found the adobe com reference of moderate help, as well as the VB scripting reference, especially when I needed to search for specific things like how to step back to a previous history state.

 The key differences between my script and Adam's are:

  • My new script exports TGA files rather than PNGs 
  • The script runs on the currently active Photoshop doc rather than recursively scanning through a folder. This is handy as it can be integrated directly into a user's workflow for rapidly updating work. 
  • Due to my current test project setup, TGA files are exported to two different folders- a Maya 'asset' location and an engine 'export' location. 
  • The source PSD is saved and control is returned to the user, rather than closing the doc. There is a bug with this step I need to stomp on before I post up a code sample. 

The key areas I am experiencing problems are:

  • Saving as TGA format has lead to a couple of hurdles concerning CS2's insistence on saving the TGA as a 'copy' if there are layers present. I get around this by saving the history state, flattening the doc, exporting the current layer, then reverting to my saved history state. The downside is that post flattening, the document thinks it's meant to stay as a TGA format, complete with the export type layer name tagged on the end, even once the layers have been restored. 
  • I intend to get around this by adding a final step that saves the document with the original .psd extension in a source folder, which I am currently working on now. 
  • Optimizing the TGA export. As the export and asset TGA files are essentially the same thing, it might work out quicker to export it once to the asset folder and then copy the output over to the export folder. 

 Additional things I intend to add:

  • Intelligent support for '_a' one bit alpha textures 
  • Support for '_g' gloss map textures
  • Easily changed options for different formats 
That's all for now!


-Pete