arkhy
arkhy

Reputation: 447

Photoshop scripting: app.activeDocument is undefined

I'm trying to access current opened document in script, but it's undefined. But i have opened document in Photoshop. Should i initialize it somehow? Here is my code

function ProcessDocumentWithoutXML()
{  
g_rootDoc      = app.activeDocument;
g_progBar      = new ProgressBar();

if (app.activeDocument != null)
{
    ProcessLayersWithoutXML(g_rootDoc);
    alert("Done!");
} else {
    alert("Missing active document");
}
}

ProcessDocumentWithoutXML();

Upvotes: 1

Views: 4212

Answers (3)

Vlad Moyseenko
Vlad Moyseenko

Reputation: 223

In my case the problem was caused by missed variable name:

function fnWithError() {
  var docName = app.activeDocument.name     // <- ExtendScript Toolkit reports error here.
  ...
  ...
  var app.activeDocument.activeLayer.bounds;// <- The real error is here.
  // the code above should be:
  // var bounds = app.activeDocument.activeLayer.bounds;
}

Upvotes: 0

Lovera
Lovera

Reputation: 192

If you are running photoshop in one window and running your code in ExtendedScript in other window you need to add the first line

"#target photoshop"

(without double marks) on your js script.

Upvotes: 0

Ghoul Fool
Ghoul Fool

Reputation: 6949

In order for it to work

g_rootDoc      = app.activeDocument;

needs to be outside the function (unless you pass in the source document to that function).

Amended code:

if (documents.length != 0)
{
   g_rootDoc = app.activeDocument;
   // g_progBar = new ProgressBar();  // no worky in cs2
   ProcessLayersWithoutXML(g_rootDoc);
   alert("Done!");
}
else
{
    alert("Missing active document");
}


function ProcessDocumentWithoutXML()
{  

}

ProcessDocumentWithoutXML();

function ProcessLayersWithoutXML()
{
}

Upvotes: 1

Related Questions