• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Is PS DOM extensible?

Advocate ,
Nov 19, 2016 Nov 19, 2016

Copy link to clipboard

Copied

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

TOPICS
Actions and scripting

Views

961

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Guest
Nov 19, 2016 Nov 19, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 19, 2016 Nov 19, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 19, 2016 Nov 19, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 19, 2016 Nov 19, 2016

Copy link to clipboard

Copied

LATEST

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

var ArtLayer = function () {};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines