Pantone ColorBook

Discussion of the xtools Toolkit

Moderators: xbytor, DavideBarranca, Paul MR

fazstp

Pantone ColorBook

Post by fazstp »

Hi X,
I modified your ColorBookDemo.js (great job btw) to select a Pantone from the Pantone solid coated color book but just had a few questions.

In your original demo the log window displays the full Pantone name but in my function below the name only shows the actual number. This is all I need to find the pantone by number but I'm just curious about why the name is different from your log window.

Secondly, is there a way to set the foregroundColor as the actual Pantone instead of the lab value of the swatch? I tried listener code but it requires bookID and name which I can't see a way of accessing.


Code: Select allfunction main() {
  if ( isPS7() ) {
    alert( "For unknown reasons, this script cannot execute in PS7 correctly." );
    return;
  }

  var folder = new Folder( app.path + "/Presets/Color Books" );
  var cb_file = "Pantone Solid Coated.acb";

  var pantone_num = prompt( 'Enter Pantone Number', '' );
  var cb = new ColorBook();
  cb.readFromFile( folder + "/" + cb_file );
  for ( var j = 0; j < cb.numberOfColors; j++ ) {
    if ( cb.colors[j].name == pantone_num ) {
      app.foregroundColor.lab = cb.colors[j].color;
      return;
    }
  }
};

fazstp

Pantone ColorBook

Post by fazstp »

This seems to work anyway as an alternative for solid coated pantones.


Code: Select allfunction getPantone() {
  var pantone_num = prompt( 'Enter Pantone Number', '' );
  if ( pantone_num == null ) {
    return false;
  }

  var pantone_name = 'PANTONE ' + pantone_num + ' C';
  var pantone_key = pantone_num + 'C';

  switch ( pantone_key.length ) {

    case 1:
      pantone_key = '     ' + pantone_key;
    break;

    case 2:
      pantone_key = '    ' + pantone_key;
    break;

    case 3:
      pantone_key = '   ' + pantone_key;
    break;

    case 4:
      pantone_key = '  ' + pantone_key;
    break;

    case 5:
      pantone_key = ' ' + pantone_key;
    break;

  }

  var desc1 = new ActionDescriptor();
  var ref1 = new ActionReference();
  ref1.putProperty( strID( 'color' ), strID( 'foregroundColor' ) );
  desc1.putReference( strID( 'null' ), ref1 );
  var desc2 = new ActionDescriptor();
  desc2.putString( strID( 'book' ), "PANTONE® solid coated" );
  desc2.putString( strID( 'name' ), pantone_name );
  desc2.putInteger( strID( 'bookID' ), 3002 );
  desc2.putData( strID( 'bookKey' ), pantone_key );
  desc1.putObject( strID( 'to' ), strID( 'bookColor' ), desc2 );

  try {
    executeAction( strID( 'set' ), desc1, DialogModes.NO );
    return true;
  } catch( err ) {
    return false;
  }
}

function strID( id ) {
  return stringIDToTypeID( id );
}

fazstp

Pantone ColorBook

Post by fazstp »

Ok I get it now. The log window is showing the displayName care of the toString function defined in the prototype.

This combo modification of the ColorBookDemo from the two functions above seems to work.


Code: Select allfunction main() {
  if ( isPS7() ) {
    alert( "For unknown reasons, this script cannot execute in PS7 correctly." );
    return;
  }

  var folder = new Folder( app.path + "/Presets/Color Books" );
  var cb_file = "Pantone Solid Coated.acb";

  var pantone_num = prompt( 'Enter Pantone Number', '' );
  var cb = new ColorBook();
  cb.readFromFile( folder + "/" + cb_file );
  for ( var j = 0; j < cb.numberOfColors; j++ ) {
    if ( cb.colors[j].name == pantone_num ) {
      setPantone( cb.colors[j] );
    }
  }
};

function setPantone( cb_color ) {
  var desc1 = new ActionDescriptor();
  var ref1 = new ActionReference();
  ref1.putProperty( strID( 'color' ), strID( 'foregroundColor' ) );
  desc1.putReference( strID( 'null' ), ref1 );
  var desc2 = new ActionDescriptor();
  desc2.putString( strID( 'book' ), cb_color.parent.title );
  desc2.putString( strID( 'name' ), cb_color.displayName );
  desc2.putInteger( strID( 'bookID' ), cb_color.parent.vendorID );
  desc2.putData( strID( 'bookKey' ), cb_color.key );
  desc1.putObject( strID( 'to' ), strID( 'bookColor' ), desc2 );

  try {
    executeAction( strID( 'set' ), desc1, DialogModes.NO );
    return true;
  } catch( err ) {
    return false;
  }

}

function strID( str_id ) {
  return stringIDToTypeID( str_id );
}

xbytor

Pantone ColorBook

Post by xbytor »

Glad you got this worked out.

Are these the only mods to the script?

If not, send me the complete modified script, and I'll roll the changes into my source tree and (eventually) out to sourceforge.

-X

fazstp

Pantone ColorBook

Post by fazstp »

Hi X,
That was the only modification. The rest of the script was waaaay over my head.


If you want the whole script you can find it in this thread on osxhints;

photoshop CS3: Keyboard shortcut for color library or set foreground color