New Document Function


While working on a script, I needed to create a new document that was 16-Bit.

Using the Photoshop DOM, you'd need to do it in two steps:

// Set the dimensions(in inches), resolution(ppi),
// name, and color mode of your document here
firstDoc = documents.add( 1, 1, 300, "Name", NewDocumentMode.RGB );
// Convert the doc to 16-bit.
app.activeDocument.bitsPerChannel = BitsPerChannelType.SIXTEEN;

This wasn't obvious to me to first create an 8-bit image and convert it. I started thinking it would be nice to have a single function where I could set all of the document properties you see in the "New File" dialog in Photoshop: Document Name, Width, Height, Resolution, Color Mode, Bit Depth, Background Contents, Pixel Aspect Ratio, and Color Profile. Using the Scripting Listener Plug-In, I grabbed some code and starting picking it apart.

I ended up with this function call.

makeDoc("Untitled", 400, 400, 300, Greyscale, 16, White, 0.9);

Here's the full newDoc.jsx script with all the routines.

I don't know if it's any better than using the Photoshop DOM, but I did learn some stuff along the way. I used conditionals to set the Color Profile based on the Color Mode. I used math to fix the assumed resolution so the pixel dimensions would come out correctly.