Photoshop scripting: app.activeDocument undefined

I am trying to access the currently open document in a script, but it is undefined. But I opened the 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(); 
+1
source share
3 answers

So that it works

 g_rootDoc = app.activeDocument; 

must be outside the function (unless you pass the source document to this function).

Modified 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() { } 
+1
source

If you run Photoshop in one window and run your code in ExtendedScript in another window, you need to add the first line

"# target photoshop"

(without double labels) on js script.

0
source

I have a similar problem guys. Could you help me with this, I have a .ai image file, and when opened through illustrator I can export to png / jpeg. But when I opened the same illustration through a script in Illustrator, I was able to open it and could not export. Can anyone help me with this?

0
source

All Articles