Calculations - determine the new Channel's name

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

Moderators: Tom, Kukurykus

undavide

Calculations - determine the new Channel's name

Post by undavide »

Hi,
I've written a simplified function for Calculations:

Code: Select allvar c2t = function(c) { return app.charIDToTypeID(c) };

// example: calculations("Rd  ", "Grn ", 50);
var calculations = function(source1, source2, opacity) {
  var d1, d2, r1, r2;
  d1 = new ActionDescriptor();
  d2 = new ActionDescriptor();
  r1 = new ActionReference();
  r2 = new ActionReference();
  d1.putClass(c2t("Nw  "), c2t("Chnl"));
  r1.putEnumerated(c2t("Chnl"), c2t("Chnl"), c2t(source1));
  d2.putReference(c2t("T   "), r1);
  d2.putUnitDouble(c2t("Opct"), c2t("#Prc"), opacity);
  r2.putEnumerated(c2t("Chnl"), c2t("Chnl"), c2t(source2));
  d2.putReference(c2t("Src2"), r2);
  d1.putObject(c2t("Usng"), c2t("Clcl"), d2);
  return executeAction(c2t("Mk  "), d1, DialogModes.NO);
};

(simplified since I don't need to use blending modes, etc).
Since I output the Calculation to a New Channel, I wonder whether there's a way to define the Channel's name, so that's easier to me to get it, later.
Or possibly the whole function returns an ActionDescriptor that contains references to the Channel itself?
Any suggestion is welcome.
Thank you!

Davide
http://www.davidebarranca.com
Mikaeru

Calculations - determine the new Channel's name

Post by Mikaeru »

undavide wrote:Since I output the Calculation to a New Channel, I wonder whether there's a way to define the Channel's name, so that's easier to me to get it, later.
I did a few tests, and unfortunately, it doesn't seem possible to add the channel's name in the main Calculation descriptor, in a way or another, so one extra step is required to rename the new channel, using the fact that it gets automatically selected:

Code: Select all    var c2t = function(c) { return app.charIDToTypeID(c) };

    // example: calculations("Rd  ", "Grn ", 50);
    var calculations = function(source1, source2, opacity, name)
    {
      var d1, d2, d3, d4, r1, r2, r3;
      d1 = new ActionDescriptor();
      d2 = new ActionDescriptor();
      r1 = new ActionReference();
      r2 = new ActionReference();
      d1.putClass(c2t("Nw  "), c2t("Chnl"));
      r1.putEnumerated(c2t("Chnl"), c2t("Chnl"), c2t(source1));
      d2.putReference(c2t("T   "), r1);
      d2.putUnitDouble(c2t("Opct"), c2t("#Prc"), opacity);
      r2.putEnumerated(c2t("Chnl"), c2t("Chnl"), c2t(source2));
      d2.putReference(c2t("Src2"), r2);
      d1.putObject(c2t("Usng"), c2t("Clcl"), d2);
      executeAction(c2t("Mk  "), d1, DialogModes.NO);
      if (name)
      {
        d3 = new ActionDescriptor();
        d4 = new ActionDescriptor();
        r3 = new ActionReference();
        r3.putEnumerated(c2t("Chnl"), c2t("Ordn"), c2t("Trgt"));
        d3.putReference(c2t("null"), r3);
        d4.putString(c2t("Nm  "), name);
        d3.putObject(c2t("T   "), c2t("Chnl"), d4);
        executeAction(c2t("setd"), d3, DialogModes.NO);
      }
    };

calculations("Rd  ", "Grn ", 50, "Red and Green");

Please note that I got rid of the return statements since, in both cases, what is returned by executeAction is not really useful here, being just a copy of the input descriptor.

HTH,

--Mikaeru
Mike Hale

Calculations - determine the new Channel's name

Post by Mike Hale »

After the make executeAction line that creates the new channel I would have added these two lines to rename the channel and return a DOM channel object.

app.activeDocument.activeChannels[0].name = name;
return app.activeDocument.activeChannels[0];
undavide

Calculations - determine the new Channel's name

Post by undavide »

Thank you guys!

Davide