Export from InDesign to Photoshop

Script for InDesign CS5-5.5. Work in progress.

Desirable scenario:

PART 1: Prepare indd document
We want to make sure every object (or group) can be exported as a separate psd layer.
1. Save open file as temp.indd file
2. If "Selected object(s)" is chosen, delete all non-selected objects, if "Complete page" is chosen, select the chosen page
3. Delete all objects that aren't on the page/bleed/slug (if this is is a big work, then ignore this step)
4. Unlock all layers
5. If "Include master" is chose, override all master page items for the first page.
6. Unlock all objects on all pages
7. Select all buttons and convert them to object (I'm not sure why but my buttons don't export to pdf)
8. Select all multistate objects and release all states to objects
9. Bring all objects to the same layer and delete all other layers

PART 2: All objects to seperate layers
Every object needs to be put on its own layer.
If an object has a script label assigned to it, then the name of the layer should be that name. If no name, they can be called something like object1, object2,...
If an object has an object style called "-text" (more info below), then "-text" should be appended to the layername, after the script label if there is one
Make sure there are no empty layers.
I have a little javascript for this with the help of people on adobe forums, but after running the script the object order is messed up, i'm not sure what's causing this. It doesn't have the layernaming option either. (see attachment: Objects to layers.jsx)
NOTE: If you think to have a better way to bring every object to photoshop, without having to put every object on its own layer in InDesign, then that's good too ofcourse!

PART 3: Bring all objects to photoshop
1. Remember Photoshop's current RGB color working space, and then set it to sRGB.
2. If "New psd" is chosen, hide all layers and export an empty pdf with the predefined pdf preset, and import it into photoshop using "crop to: media box" so we have an empty document with the correct dimensions
If "Add to open psd" is chosen, then first make a new snapshot of that psd, and add all layers to this psd
3. Bring the layer to photoshop, start with the bottom layer:
Not all text needs to be editable into photoshop. I will give all editable text an object style called "-text".
-- BEGIN LOOP--
1. Remember the layer name
2. If the layer has "-text" into its name, start the INDD2PSD TEXT FUNCTION, otherwise start the INDD2PSD RASTER FUNCTION
3. Rename the photoshop layer with the remembered name
4. Go to the next layer and repeat these steps until all layers are done
-- END LOOP--
4. Crop off cropmarks
5. Add to or make existing layer comp (save only visibility)
6. Restore Photoshop's RGB color working space

INDD2PSD RASTER FUNCTION
See the apple script i sent to you (i put it again in attachment: Pages to PS Layers + CROP.scpt + ExportToPS joboptions). I'm not sure if you think this code is usable, or if you rather start from scratch.
1. Make all layers invisible except for the one that we want to bring to photoshop
3. Export a temp.pdf of this file using a predefined pdf preset (which contains bleed marks)
4. Import the pdf into photoshop using "crop to: media box"
5. Move the layer to the psd file

INDD2PSD TEXT FUNCTION
1. Read from InDesign text object: width, height and position
2. In Photoshop, make new area type with these dimensions and position
--BEGIN LOOP--
1. Read font style properties (see below) of the first character
2. Select all characters after this until a character with different font style properties is found
3. Copy text to Photoshop and apply font style properties
4. Move on to the next character and repeat steps above, until all text is copied into Photoshop
--END LOOP--

FONT STYLE PROPERTIES: (this is what can be turned into css)
character:
- fill color
- font family
- font size
- leading
- font style: this is a special one: only if the style is "Bold Italic", "Bold" or "Italic", then these should be turned into faux bold/italic (the font style should remain "Regular" in Photoshop)
- underline: just check if it's on or off
- striketrough: just check if it's on or off
paragraph:
- alignment
- left indent
- right indent
- space before
- space after

PART 4: Clean up
1. Close temp.indd, don't save
2. Delete temp.pdf files
3. "Done!"

Prerequisites:

1. Activate the page you want to export.

The script works on page by page basis: only the active page will be exported to psd-file.

2. Run the script.
A dialog box will appear. However, it only OK and Cancel buttons work so far.

The script removes all pages except the active and saves the active document with a new file name: the original base name plus hyphen and the active page number.

Then a temporary folder is created -- that's where temporary pdf-files are saved (I can delete them at the end of the script, of course if you want).

Every object is moved to a separate layer which is exported to a separate pdf-file and rasterized to a separate layer in the psd-file. The bottom layer is the "Background" -- you can Opt+click its eye to make all other layers invisible.

Click here to download the script.