Skip to main content
DBarranca
Legend
November 19, 2016
Question

Is PS DOM extensible?

  • November 19, 2016
  • 2 replies
  • 1176 views

Hi,

apparently InDesign implementation of ExtendScript allows DOM extension (see this thread).

Basically you can add to a Class (say, an InDesign 'Cell') a new method.

I was wondering whether the same is theoretically possible. My goal is to fill PS DOM gaps with ActionManager functions, to be attached (say) to ArtLayers.

As an example, there's no DOM way to script a Hue/Saturation adjustment, and I can easily build my AM function for that matter. But it would run autonomously, and not as an actual ArtLayer method. E.g.

function applyHueSat(opt) {

  // ... Long ActionManager implementation

}

Layer.prototype.applyHueSat = applyHueSat;

app.activeDocument.activeLayer.applyHueSat(/* whatever */);

Of course the above doesn't work (line 04 is the culprit). I know I can operator overload "classic" Classes, but I haven't been able to find a way in Photoshop to properly extend the DOM.

Is this possible?

Thank you,

Davide

This topic has been closed for replies.

2 replies

SuperMerlin
Inspiring
November 19, 2016

Michel beat me to it

var ArtLayer = function () {}

ArtLayer.prototype.applyHueSat = function(Hue,Sat,Light){

    var desc9 = new ActionDescriptor();

    desc9.putBoolean( charIDToTypeID('Clrz'), false );

        var list2 = new ActionList();

            var desc10 = new ActionDescriptor();

            desc10.putInteger( charIDToTypeID('H   '), Hue );

            desc10.putInteger( charIDToTypeID('Strt'), Sat );

            desc10.putInteger( charIDToTypeID('Lght'), Light );

        list2.putObject( charIDToTypeID('Hst2'), desc10 );

    desc9.putList( charIDToTypeID('Adjs'), list2 );

    executeAction( charIDToTypeID('HStr'), desc9, DialogModes.NO );

};

activeDocument.activeLayer.applyHueSat(128,70,90);

DBarranca
DBarrancaAuthor
Legend
November 19, 2016

Thank you both,

you've far better memory than me :-) (that's remarkably easy, though)

So, SuperMerlin​ basically you're working around the "Class not loaded unless used" issue that is mentioned in the PS-Scripts thread this way?

var ArtLayer = function () {}

That's neat. Do you think it might be worth checking in advance? like:

if (typeof ArtLayer === 'undefined') {

    ArtLayer = function() {}; // global, btw

}

Thank you,

Davide

SuperMerlin
Inspiring
November 19, 2016

I'm lazy and if one line will do, I prefer it.

var ArtLayer = function () {};

November 19, 2016

Hi Davide,

I kind of remember that other developers have already tried to extend the PS DOM in the past, but ran into some issues:

Extending PS Objects - PS-SCRIPTS.COM

Extending ArtLayer - PS-SCRIPTS.COM

HTH,

--Michel