Skip to main content
StrongBeaver
Legend
June 29, 2015
Question

psdom

  • June 29, 2015
  • 3 replies
  • 1481 views

I'm beginning in scripting using ps-dom.  What I want is to create a new document, that is 120x200, followed by adding another layer to the current document. The following code isn't working ?

var psdoc = app.documents.add(120,200)

psdoc.activeDocuments.layers.add()

This topic has been closed for replies.

3 replies

Participating Frequently
July 1, 2015

Hi StrongBeaver

as the topic for which you opened this thread has received the right answer you should flag it as "answered".

matias.kiviniemi
Legend
June 29, 2015

I've noticed that creating a document with high resolution in Javascript can fail even if you can create same doc from the menu. I think I tried to create a 4096x4096@300PPI and had to drop to 72 PPI.

StrongBeaver
Legend
June 29, 2015

Creating a 300dpi with JS will cause problems, thanks for the tip !

StrongBeaver
Legend
June 29, 2015

Must I set the units and the ruler units, can't it go by whatever defaults are set for Ps ?

I declared the resolution for the variable psdoc and still get an error on this line;

var psdoc = app.documents.add(120,200,72)

JJMack
Community Expert
Community Expert
June 29, 2015

Perhaps this may work

var startRulerUnits = app.preferences.rulerUnits; // save users current unit setting

app.preferences.rulerUnits = Units.PIXELS; // tell ps to work with pixels

var psdoc = app.documents.add(120,200, 72); // open new document width height res default the rest

newLayer = psdoc.artLayers.add(); // add a new art layer var newLayer

newLayer.name = "New Layer"; // set the new layer name to "New Layer"

JJMack
StrongBeaver
Legend
June 29, 2015

I didn't declare a resolution for the new document, arghh.