• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

psdom

Advisor ,
Jun 28, 2015 Jun 28, 2015

Copy link to clipboard

Copied

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()

TOPICS
Actions and scripting

Views

788

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Jun 28, 2015 Jun 28, 2015

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jun 28, 2015 Jun 28, 2015

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 28, 2015 Jun 28, 2015

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jun 28, 2015 Jun 28, 2015

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jun 28, 2015 Jun 28, 2015

Copy link to clipboard

Copied

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)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 29, 2015 Jun 29, 2015

Copy link to clipboard

Copied

If you copy and paste the code I posted into notepad and save it as psdom.jsx and then drop it on photoshop. You will see this.  I can not type do you think I post extra line of code for fun? In fact I left left out a line at the end thought you may figure it out.

app.preferences.rulerUnits = startRulerUnits; //restore users units

In my case the rules would be back in inches not displayed in pixels.  Woild be 1.66" wide by 2.77" high.

Capture.jpg

Capture.jpg

Capture.jpg

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 29, 2015 Jun 29, 2015

Copy link to clipboard

Copied

JJMacks code is the right way to do it using the DOM. As mentioned, you didn't add the resolution in your example. Also, this line it totally wrong:

psdoc.activeDocuments.layers.add()

psdoc is your document that you just created. It doesn't have any activeDocuments. You can make it an active document by stating:

psdoc = app.activeDocument.

As JJMack all ready mentioned, the way to add a layer is artLayers.Add() rather than just layers.add().

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jun 29, 2015 Jun 29, 2015

Copy link to clipboard

Copied

I have to declare the size as a string along with the measurement units.  I didn't have to declare the rulerUnits as I originally though in the beginning as JJMack did in his first & second screen capture, that is what I wanted to know and I got my answer

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jul 01, 2015 Jul 01, 2015

Copy link to clipboard

Copied

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

newLayer = psdoc.artLayers.add();

newLayer.name = "NewName";

Have patience, if you don't well please don't reply

I know the syntax for creating an Array, not sure how to create an array of artLayers with each artLayer having their own name, when the script is executed X number of Layers are created with the respectful names ?

var LayerList = ["one","two","three","four","five"]

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 01, 2015 Jul 01, 2015

Copy link to clipboard

Copied

If you would use your eyes and read and the help we try to give you. You would not have ask questions you have been given a solution for.

If  you do not set the units,  You will not know what size document would be created if a document was added. For if the user had set units to percent and you did not set the units there would be a scripting error because a passing was percentage would be and invalid argument for the add document statement.

In my example code I posted for you I also showed the correct way to add a layer and then to name that layer added. The code was commented  and I even posted screen capture showing the result of running the code.  I pointed out I omitted a line of code to restote the users ruler units therefore the rulers unites were shown in pixels in the screen capture.  I then added the missing line of code.  Fixed up my Photoshop Preferences setting ruler units to inches which Is my normal setting.  I then ran the Script again and this time the ruler units were shown in inches not pixels as the second screen capture showed.

You seem to want to tell us that we were wrong that you did not have to set units.  That is true you do have to but if you do not the add document statement may generate a scripting error which your code would not catch so the script would fail with an error.  The way you would code your statement to catch your error would be like this.

try {var psdoc = app.documents.add(120,200);}

catch(e) { alert(e);}

You would need to loop through your array adding a layer each iteration and name the layer added each time you add the new layer.

artLayer.add() add a single layer not an array of layers. Look at page 65 in Photoshop CC javascripting guide.

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jul 01, 2015 Jul 01, 2015

Copy link to clipboard

Copied

If you would use your eyes and read and the help we try to give you. You would not have ask questions you have been given a solution for.

Yes, but I do use my eyes, what else can I use to read that I'm unaware of.

If  you do not set the units,  You will not know what size document would be created if a document was added. For if the user had set units to percent and you did not set the units there would be a scripting error because a passing was percentage would be and invalid argument for the add document statement.

The point was not whether or not the units were set, I did not care about that, the point was strictly to get the script to run, period. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jul 01, 2015 Jul 01, 2015

Copy link to clipboard

Copied

Leave things as is, I will look though the CC Javscript guide, ok !

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 01, 2015 Jul 01, 2015

Copy link to clipboard

Copied

Yes that is a problem. The point is you should care but you do not care.  You should want to learn but most of the time you do not seem willing to learn.  Users run out of  patience with you.  You do not seem to grasp what is important.  We try to help but you do not care for our help.  That is very disrespectful to say the least.

Capture.jpg

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jul 01, 2015 Jul 01, 2015

Copy link to clipboard

Copied

I simply didn't care because wanted to understand the bare minimum, how it was perceived, to each his own. If it's disrespectful, well then it's going to have to be taken as that.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 01, 2015 Jul 01, 2015

Copy link to clipboard

Copied

Since  you want to persist with your attitude I will put you on my ignore list like I'm sure many other have done. I the past I resisted doing that. Now I resign will no longer waste time reading what you write.

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 01, 2015 Jul 01, 2015

Copy link to clipboard

Copied

LATEST

Hi StrongBeaver

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines