skip to Main Content

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

3

Answers


  1. 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()
    {
    }
    
    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
  3. 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;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search