Skip to main content
Participant
July 5, 2019
Question

Javascript Question [evalScript] (Photoshop Panel)

  • July 5, 2019
  • 2 replies
  • 471 views

I am currently delving into CEP and Panel creation. I have a button that runs the function below. The event essentially creates a document and names the document to the name stored in the variable in "docName". The code below works:

function creteDoc() {

  var docName = "MyDocument"

  exec = 'documents.add(500, 500, 72, "' + docName +'")';

  csInterface.evalScript(exec);

}

However, I the code doesn't run when I change this line:

exec = 'documents.add(500, 500, 72, "' + docName +'")';

TO

exec = "documents.add(500, 500, 72, " + docName + ")";

Why I am asking is because I want to use the button name (this.name) which is "500" to change the size of the document essentially ending up with:

exec = "documents.add(" + this.name + "," + this.name + ", 72, " + docName + ")";

Writing the code above will not run, unless the docName is a number.
exec = "documents.add(" + this.name + "," + this.name + ", 72, " + this.name + ")"; <- works
Any insight or help will be appreciated! Thank you!
This topic has been closed for replies.

2 replies

PECourtejoie
Community Expert
Community Expert
January 15, 2020

Hello, I'm moving this to the exchange forum.

Ten A
Community Expert
Community Expert
August 17, 2019

You can use template literal like below.

var wd = ht = 500,

var docName = "testDocument";

var csi = new CSInterface();

var exc = `app.documents.add(${wd}, ${ht}, 72, "${docName}")`;

csi.evalScript(exc);

Extension Builder already discontinued, and this place already dead too.

However, you can ask about extensions in Extensions / Add-ons Development.