Reading Layer Information = Painfully Slow ->XMP?

Discussion of Photoshop Scripting, Photoshop Actions and Photoshop Automation in General

Moderators: Tom, Kukurykus

dennitzio

Reading Layer Information = Painfully Slow ->XMP?

Post by dennitzio »

I have been working on a script that goes through large PSDs, looks at the layer types, and exports the results to a text file. The script writes each top layerset, then goes into each layer, checks if it's a text layer, and if so, writes the text to a .txt file.

The problem I'm having is that any time the script accesses layer information, that access is extremely slow (28 seconds on an 84 layer 1920x1080 PSD on CS5 in a Win7x64 24-thread Xeon w/24GB RAM). From every test I've done, I haven't found a way to improve the speed. Moreover, it gets slower and slower with big files - so a very large file can start off at <1sec/layer and end up taking 10sec/layer. I wrote an inelegant, simple script to test this from the ExtendScript ToolKit. All the layers have to be at the top level (no layerset parsing here):

Code: Select allvar layernum = 0
var layerinfo = ""
var totallayers = app.activeDocument.layers.length
var layername = ""

function getlayerinfo() {
   
    if (layernum >= totallayers) {
        $.writeln ("no more layers");
        }
   
    else {
         layerinfo = app.activeDocument.layers[layernum];
         layername = layerinfo.name;
         $.writeln(layernum);
         $.writeln(layerinfo);
         $.writeln(layername);
        return goagain();
        }
   
    return ("ok");
}
   
function goagain() {
    layernum = layernum+1;
    getlayerinfo();
}
   
    $.writeln("\r\r\r---------Start")
    getlayerinfo();
    "---------End"
It's clear that about 98% of the elapsed time is in one place: layerinfo = app.activeDocument.layers[layernum];. Everything else runs pretty quickly. Any additional query to that layer runs faster, but still slower than almost anything else in a script - especially if a function is passing the data on to another object's request.

At this point I think nothing can be done to improve the speed of this with this method. Unless someone knows something else, I'm going to start looking at using the XMP metadata baked in the PSD instead. I see master xbytor has some XMP scripts that I'll jump into, but if anyone has any suggestions of finished scripts to look at - and more importantly, what the timings are like with an XMP method by comparison - I'd love to see them!

Thanks! Den

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

txuku

Reading Layer Information = Painfully Slow ->XMP?

Post by txuku »

Bonjour dennitzio

Maybe using Scriptlistener ?
dennitzio

Reading Layer Information = Painfully Slow ->XMP?

Post by dennitzio »

Thanks for the suggestion - I'll look at it, but I suspect it's just Photoshop doing its thing. I think I need a plugin to convert my script to using the XMP! ; )
xbytor

Reading Layer Information = Painfully Slow ->XMP?

Post by xbytor »

If you have a lot of layers and using the DOM is too slow, you need to use the Action Manager (ActionDescriptor/Reference/List) API.
There has been much discussion here and elsewhere and somebody may actually have a library of routines for this. Mike Hale and
Trevor Morris are two people that have done a lot of work in this area.

I don't have this problem because I don't have that many layers :)
dennitzio

Reading Layer Information = Painfully Slow ->XMP?

Post by dennitzio »

xbytor wrote:If you have a lot of layers and using the DOM is too slow, you need to use the Action Manager (ActionDescriptor/Reference/List) API.

Thank you xbytor! You've proved your supreme excellence once again. I'm going to check into those. My next plan was to just take the process out of Photoshop entirely and build a Python standalone that parses the PSD using Adobe's PSD specs. But I prefer a tool that runs on top of Photoshop/Bridge so I appreciate the alternative! I'll do some searching on those keywords and see what I find.