Apply a gradient to a selection

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

Moderators: Tom, Kukurykus

rcvalle

Apply a gradient to a selection

Post by rcvalle »

Hi,

Is it possible to apply a linear gradient fill, with dither and transparency, to a given selection, from within a script? Thanks in advance.

Best regards,

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

txuku

Apply a gradient to a selection

Post by txuku »

Hello rcvalle

I think you can do with ScriptingListenerJS log ?
rcvalle

Apply a gradient to a selection

Post by rcvalle »

Actually, I was looking at how to do this without using the Action Manager.
jfriedl

Apply a gradient to a selection

Post by jfriedl »

Actually, I was looking at how to do this without using the Action Manager

I think txuku was suggesting something along the lines of:

Code: Select allfunction foo()
{
    var V1 = new ActionDescriptor();
    var V2 = new ActionDescriptor();
    V2.putUnitDouble(charIDToTypeID("Hrzn"),charIDToTypeID("#Pxl"), 118.000000); // start point X
    V2.putUnitDouble(charIDToTypeID("Vrtc"),charIDToTypeID("#Pxl"), 94.000000);  // start point Y
    V1.putObject(charIDToTypeID("From"),charIDToTypeID("Pnt "), V2);
    var V3 = new ActionDescriptor();
    V3.putUnitDouble(charIDToTypeID("Hrzn"),charIDToTypeID("#Pxl"), 681.000000); // end point X
    V3.putUnitDouble(charIDToTypeID("Vrtc"),charIDToTypeID("#Pxl"), 858.000000); // end point Y
    V1.putObject(charIDToTypeID("T   "),charIDToTypeID("Pnt "), V3);
    V1.putUnitDouble(charIDToTypeID("Opct"),charIDToTypeID("#Prc"), 100); // opacity
    V1.putEnumerated(charIDToTypeID("Type"),charIDToTypeID("GrdT"),charIDToTypeID("Lnr ")); // type (Linear)
    //V1.putEnumerated(charIDToTypeID("Md  "),charIDToTypeID("BlnM"),stringIDToTypeID("lighterColor")); // blend mode (leave this out for "Normal")
    V1.putBoolean(charIDToTypeID("Dthr"), true); // yes, use Dither
    V1.putBoolean(charIDToTypeID("UsMs"), true);
    var V4 = new ActionDescriptor();
    V4.putString(charIDToTypeID("Nm  "), "$$$/DefaultGradient/BlackWhite=Black, White"); // name of gradient to use
    V4.putEnumerated(charIDToTypeID("GrdF"),charIDToTypeID("GrdF"),charIDToTypeID("CstS"));
    V4.putDouble(charIDToTypeID("Intr"), 4096.000000);
    var V5 = new ActionList();
    var V6 = new ActionDescriptor();
    var V7 = new ActionDescriptor();
    V7.putDouble(charIDToTypeID("Cyn "), 75.020000);
    V7.putDouble(charIDToTypeID("Mgnt"), 68.010000);
    V7.putDouble(charIDToTypeID("Ylw "), 67.000000);
    V7.putDouble(charIDToTypeID("Blck"), 90.190000);
    V6.putObject(charIDToTypeID("Clr "),charIDToTypeID("CMYC"), V7);
    V6.putEnumerated(charIDToTypeID("Type"),charIDToTypeID("Clry"),charIDToTypeID("UsrS"));
    V6.putInteger(charIDToTypeID("Lctn"), 0);
    V6.putInteger(charIDToTypeID("Mdpn"), 50);
    V5.putObject(charIDToTypeID("Clrt"), V6);
    var V8 = new ActionDescriptor();
    var V9 = new ActionDescriptor();
    V9.putDouble(charIDToTypeID("Cyn "), 0.000000);
    V9.putDouble(charIDToTypeID("Mgnt"), 0.000000);
    V9.putDouble(charIDToTypeID("Ylw "), 0.000000);
    V9.putDouble(charIDToTypeID("Blck"), 0.000000);
    V8.putObject(charIDToTypeID("Clr "),charIDToTypeID("CMYC"), V9);
    V8.putEnumerated(charIDToTypeID("Type"),charIDToTypeID("Clry"),charIDToTypeID("UsrS"));
    V8.putInteger(charIDToTypeID("Lctn"), 4096);
    V8.putInteger(charIDToTypeID("Mdpn"), 50);
    V5.putObject(charIDToTypeID("Clrt"), V8);
    V4.putList(charIDToTypeID("Clrs"), V5);
    var V10 = new ActionList();
    var V11 = new ActionDescriptor();
    V11.putUnitDouble(charIDToTypeID("Opct"),charIDToTypeID("#Prc"), 100.000000);
    V11.putInteger(charIDToTypeID("Lctn"), 0);
    V11.putInteger(charIDToTypeID("Mdpn"), 50);
    V10.putObject(charIDToTypeID("TrnS"), V11);
    var V12 = new ActionDescriptor();
    V12.putUnitDouble(charIDToTypeID("Opct"),charIDToTypeID("#Prc"), 100.000000);
    V12.putInteger(charIDToTypeID("Lctn"), 4096);
    V12.putInteger(charIDToTypeID("Mdpn"), 50);
    V10.putObject(charIDToTypeID("TrnS"), V12);
    V4.putList(charIDToTypeID("Trns"), V10);
    V1.putObject(charIDToTypeID("Grad"),charIDToTypeID("Grdn"), V4);
    executeAction(charIDToTypeID("Grdn"), V1, DialogModes.NO);
}
rcvalle

Apply a gradient to a selection

Post by rcvalle »

I will make a function from this code. Thank you!