Annotation functions.

Photoshop Script Snippets - Note: Full Scripts go in the Photoshop Scripts Forum

Moderators: Tom, Kukurykus

Paul MR

Annotation functions.

Post by Paul MR »

A few functions that work for CS2/CS3

Code: Select all///////////////////////////////////////////////////////////////////////////////////
// Returns the number of notes
///////////////////////////////////////////////////////////////////////////////////
function maxNotes(){
var a=0;
while(1){
if(showHideAnno('Hd  ',a)){
   a++;}else{return a;}}
};
///////////////////////////////////////////////////////////////////////////////////
// Create a new note at position x,y
///////////////////////////////////////////////////////////////////////////////////
function makeAnnotation(posX,posY) {
  function cTID(s) { return app.charIDToTypeID(s); };
  function sTID(s) { return app.stringIDToTypeID(s); };
    var desc30 = new ActionDescriptor();
        var ref12 = new ActionReference();
        ref12.putClass( sTID('annotation') );
    desc30.putReference( cTID('null'), ref12 );
        var desc31 = new ActionDescriptor();
            var desc32 = new ActionDescriptor();
            desc32.putUnitDouble( cTID('Hrzn'), cTID('#Pxl'), posX );
            desc32.putUnitDouble( cTID('Vrtc'), cTID('#Pxl'), posY );
        desc31.putObject( cTID('Lctn'), cTID('Pnt '), desc32 );
            var desc33 = new ActionDescriptor();
            desc33.putUnitDouble( cTID('Hrzn'), cTID('#Pxl'), 240.000000 );
            desc33.putUnitDouble( cTID('Vrtc'), cTID('#Pxl'), 140.000000 );
        desc31.putObject( cTID('Sz  '), cTID('Ofst'), desc33 );
        desc31.putEnumerated( sTID('annotType'), sTID('annotType'), sTID('annotText') );
    desc30.putObject( cTID('Usng'), sTID('annotation'), desc31 );
    executeAction( cTID('Mk  '), desc30, DialogModes.NO );
};
///////////////////////////////////////////////////////////////////////////////////
// Show or Hide a note
//'Shw  ' or 'Hd   ' , Annotation number
///////////////////////////////////////////////////////////////////////////////////
function showHideAnno(showHide,number) {
  function cTID(s) { return app.charIDToTypeID(s); };
  function sTID(s) { return app.stringIDToTypeID(s); };
    var desc9 = new ActionDescriptor();
        var ref3 = new ActionReference();
        ref3.putIndex( sTID('annotation'), number ); //Annotation number
    desc9.putReference( cTID('null'), ref3 );
   try{
    executeAction( cTID(showHide), desc9, DialogModes.NO );
   return true;
   }catch(e){
         return false;
      }      
};

///////////////////////////////////////////////////////////////////////////////////
// Enter text into note
// text string, note number
///////////////////////////////////////////////////////////////////////////////////
function addAnnoText(string,noteNumber) {
  function cTID(s) { return app.charIDToTypeID(s); };
  function sTID(s) { return app.stringIDToTypeID(s); };
    var desc47 = new ActionDescriptor();
        var ref21 = new ActionReference();
        ref21.putIndex( sTID('annotation'), noteNumber );
    desc47.putReference( cTID('null'), ref21 );
        var desc48 = new ActionDescriptor();
       desc48.putData( cTID('TxtD'), string );
    desc47.putObject( cTID('T   '), sTID('annotation'), desc48 );
    executeAction( cTID('setd'), desc47, DialogModes.NO );
};
Patrick

Annotation functions.

Post by Patrick »

Paul, do you have any way of reading the contents (text) of a note? This is something I tried awhile back with no success.

Patrick
Paul MR

Annotation functions.

Post by Paul MR »

Not as yet Patrick, I'm still trying.. could be a long time
Mike Hale

Annotation functions.

Post by Mike Hale »

Paul,

I think you will find that you can not use Photoshop to read any info about notes. It's one of the objects that the AM API can put but not get.

Patrick,

I thought you were happy with the exiftool method I came up with here http://ps-scripts.com/bb/viewtopic.php?t=1689

Mike
Patrick

Annotation functions.

Post by Patrick »

Mike, you are right that did do what I needed (I completely forgot about that thread!). I was just curious if Paul figured out a direct way of doing it.

Patrick
JohnK

Annotation functions.

Post by JohnK »

It seems CS3 has a slight issue when it comes to using a string to put into the note. I have found that if I use
Code: Select allString.fromCharCode( )
it works every time.

If I use Code: Select allvar nStr = "Test" as the example the CharCode will be Code: Select allString.fromCharCode( 255, 254, 84, 0, 101, 0, 115, 0, 116, 0 )

If I do the following to try and return the character code for each letter the array will return the correct sequence.

Code: Select allvar nStr = "Test"
var nArr = [];
nArr[0] = 255;
nArr[1] = 254;
var t=0;
while (t <=nStr.length-1){
nArr.push(nStr.charCodeAt(t));
nArr.push(0);
t++
}
$.write(nArr); //will return 255, 254, 84, 0, 101, 0, 115, 0, 116, 0


Is Code: Select allString.fromCharCode( 255, 254, 84, 0, 101, 0, 115, 0, 116, 0 ) the same as Code: Select allString.fromCharCode( nArr )

Cheers,

John.
xbytor

Annotation functions.

Post by xbytor »

Then doing these should work as well:

Code: Select allvar str = String.fromCharCode( 255, 254) + "Test";

or

Code: Select allvar str = "\uFFFE" + "Test";


This should give you the 0xFFFE marker that you need for the first 16 bits, plus the rest of the string in Unicode.

The best reference that I have that works with multiple version of PS is xtools/xlib/Stream.js for doing binary string manipulations.