0

I have a Pantone color, say "PANTONE 3135 C", and I would like to assign it to a channel in Photoshop (CC 2015, with ExtendScript 4.5.5, Toolikt CC 4.0.0.1) using JavaScript/ExtendScript.

To do this manually, I'd select the channel, double-click, click the "Color" box, click "Color Libraries", and then choose the respective Pantone color.

I could not find any way to script this online. The help is of little help (no mention of Pantone in the Javascript CS6 reference, although it does suggest the color has to be/is a SolidColor). I've tried manually selecting a Pantone color and seeing what Photoshop will tell me about its type by running

$.writeln( app.activeDocument.channels[0].color )

(which would normally print [SolidColor] for a regular solid color), but got a run-time error message saying "This version of the ScriptingSupport does not support custom colors such as PANTONE (r) colors."

I now suspect that I indeed cannot do this form a script. Before I restore to a Pantone -> RGB/Lab conversion/lookup table, I'd like to ask:

  1. Is there a way to assign a Pantone color from JavaScript/ExtendScript?
  2. Is there a way to achieve this using actions? (keeping in mind that the pantone color and channel will be different every time and have to be parametrizable).

Thanks!

  • Have you tried running the script listener? It can document for you things thst are not documented with atomic calls. The redults arent pretty but workable. Sometimes even understandable. Welcome to GD.SE – joojaa Aug 14 '15 at 6:34
  • @joojaa I haven't. Will try it as soon as I get to my work computer. Thanks! – Jan Benes Aug 15 '15 at 13:19
  • @joojaa that actually worked :-) thanks for the tip. I'll post the relevant part of my solution script (some editing was required) tomorrow after cleaning it up a bit. Alternatively, feel free to post an answer yourself. – Jan Benes Aug 20 '15 at 17:47
1

As per @joojaa's suggestion, I used Adobe's script listener plug-in to make Photoshop output JavaScript code for what the user currently does. I modified this output so that, instead of a fixed color, it takes the pantone name as a parameter.

Below is a JavaScript/EffectScript function for setting the color of the currently selected channel to a specific pantone color.

// Assign a pantone color and solidity (0.0-100.0) to the current channel
function setPantoneColor(pantoneName, solidity) {
    if(typeof solidity !== "undefined" && (solidity < 0.0 || solidity > 100.0)) {
        throw new Error("Solidity needs to be between 0.0 and 100.0, parameter value was " + solidity)
    }

    var idsetd = charIDToTypeID( "setd" );
    var desc1 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
    var ref = new ActionReference();
    var idChnl = charIDToTypeID( "Chnl" );
    var idOrdn = charIDToTypeID( "Ordn" );
    var idTrgt = charIDToTypeID( "Trgt" );
    ref.putEnumerated( idChnl, idOrdn, idTrgt );
    desc1.putReference( idnull, ref );
    var idT = charIDToTypeID( "T   " );
    var desc2 = new ActionDescriptor();

    /* 
     set channel name - we don't want this

     var idNm = charIDToTypeID( "Nm  " );
     desc2.putString( idNm, pantoneName );
     */

    // color
    var idClr = charIDToTypeID( "Clr " );
    var desc3 = new ActionDescriptor();
    // set the color book to use
    var idBk = charIDToTypeID( "Bk  " );
    desc3.putString( idBk, """PANTONE+® Solid Coated""" );
    // set the color name
    var idNm = charIDToTypeID( "Nm  " );
    desc3.putString( idNm, pantoneName );

    /*
     haven't observed any difference when those were left out

     var idbookID = stringIDToTypeID( "bookID" );
     desc3.putInteger( idbookID, 3060 );
     */
    /*
     the code seems to be in ASCII and represent a non-standard pantone ID        

     var idbookKey = stringIDToTypeID( "bookKey" );
     desc3.putData( idbookKey, String.fromCharCode( 79, 82, 48, 50, 49, 67 ) );
     */
    // back color?
    var idBkCl = charIDToTypeID( "BkCl" );
    desc2.putObject( idClr, idBkCl, desc3 );

    if(typeof solidity !== "undefined") {
        // opacity (#prc = number of percent?)
        var idOpct = charIDToTypeID( "Opct" );
        var idPrc = charIDToTypeID( "#Prc" );  
        desc2.putUnitDouble( idOpct, idPrc, solidity);
    }

    // SCch - set color channel?
    var idSCch = charIDToTypeID( "SCch" );
    desc1.putObject( idT, idSCch, desc2 );
    executeAction( idsetd, desc1, DialogModes.NO );
}

To use this, one also needs to set the current channel:

// select a photoshop channel with the given name
function selectChannel(channelName) {
    var idslct = charIDToTypeID( "slct" );
    var desc = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
    var ref = new ActionReference();
    var idChnl = charIDToTypeID( "Chnl" );
    ref.putName( idChnl, channelName );
    desc.putReference( idnull, ref );
    executeAction( idslct, desc, DialogModes.NO );
 }

You can use them like this:

selectChannel("Name of the channel we want to set a pantone color for")
setPantoneColor("PANTONE Blue 072 C")
// alternatively, we can also set the solidity
//setPantoneColor("PANTONE Blue 072 C", 75.0)

Technical side-note: I commented out pieces of code that don't seem to serve any purpose. Especially the line containing "bookKey" would be difficult to reverse engineer, as the number (ASCII) codes represent what seems to be adobe's proprietary, fixed-size, pantone ID (e.g. PANTONE Black 6 C would set the code on this line to 66, 76, 65, 75, 54, 67, which are ASCII codes for BLAK6C). Luckily, all seems well even without those lines.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.