Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Thumbnail selections, events and selection lists

New Here ,
Sep 15, 2005 Sep 15, 2005
I'm experimenting with creating an external data file to track Bridge selections. I've come across two problems, one of which I have found a fix for, the other not.

If I obtain 'app.document.selections' following a 'select' event type, the list I get is actually the list prior to the latest selection. So if I had test1.jpg selected and switch to test2.jpg, app.document.selections[0] will be test1.jpg. The same applies to using 'deselect' that actual deselection does not show in the app.document.selections list when the event is triggered.

The fix for this is to use event type 'preview' which returns the latest selections at the moment you change the selection.

Unfortunately, preview does not update when you click when you deselect - and since deselect and select events both seem to come ahead of the updating of the selections list, using them does not work.

Any suggestions / ideas on this.

Andrew

Here is the code I am currently using:

onThumbnailEvent = function( event ){
if( event.object.constructor.name == "Thumbnail" ){
if( event.type == "preview" ) {
ah_CollectBridgeData();
return {handled:true};//stop processing event handlers
}
}
}

ah_writeData = function (tFile,tString) {
if (tFile.open('w')) {
if (tFile.write(tString)) tFile.close();
else throw ("Error saving file list\n" + tFile);
}
else throw ('Error, Data File Not Opened\n' + tFile);
}

ah_CollectBridgeData = function () {
var tFile = new File ('/c/Program Files/Adobe/Adobe Photoshop CS2/Presets/Scripts/nn-test3.dat');
var filestr = ah_fileThumbnailsToFilestr(app.document.selections);
ah_writeData(tFile,filestr);
}

ah_fileThumbnailsToFilestr = function( thumbnails ) {
var fileAr = new Array();
for ( var i = 0; i < thumbnails.length; i++ ) {
if(thumbnails.spec instanceof File) fileAr.push(thumbnails[ i ].spec);
}
return fileAr.toString();
}

// register the handler
allDocEventHandlers = { handler: onThumbnailEvent };
app.eventHandlers.push( allDocEventHandlers );
TOPICS
Scripting
528
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 15, 2005 Sep 15, 2005
I don't have time to test this right now - but here's an idea

event.object will be a thumbnail and should be the thumbnail that caused the event ( the one selected or the one deselected).

suggest executing a copy of app.document.selections and adding/subtracting the event.object in the process - then do the write.

Bob
Adobe WAS Scripting
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 15, 2005 Sep 15, 2005
Thanks Bob, I'll try working with that - the main problem is when you have say 10 images selected and then you deselect all (for example clicking on an empty part of the content window), would event.object reflect that.

Andrew

Incidentally - the support you provide here (and elsewhere) really is outstanding.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 15, 2005 Sep 15, 2005
LATEST
ugh, hadn't thot that thru yet on the deselect...

Looks like you get "n" deselects in a row.

Run this in ESTK, keep estk's console visible then select/deselect in bridge...

#target bridge

EventWatcher = {};
EventWatcher.lastEvent = "";

EventWatcher.eventCatcher = function( evt ) {
$.writeln( evt.type + " Event" );
if ( evt.type == "deselect" ) {
$.writeln( "Thumbnail Deselect: " + evt.object.path );
// debugger;
}
EventWatcher.lastEvent = evt;
return { handled: false };
}

app.eventHandlers.push( { handler: EventWatcher.eventCatcher } );

All the deselects (on a multiple deselect) happen in a row, and you're only interested in the last one, and you're not even interested in that. app.document.selections will be correct on the event (regardless of type) after the last deselect.

Hold off doing anything on a deselect until the event type changes.

if ( event.type = "deselect" ) {
myNamespace.loadedGun = true;
} else {
if ( myNamespace.loadedGun ) {
nowWriteMySelectionFile();
}
}

Since it's possible that you won't get another event for some time, you might want to setup a scheduled task that checks to see if the "gun is loaded", and if so to write the files.

Thanks for the kind words. I really enjoy working with everyone. It's a great break from head-down coding, and I learn something from just about every case.

Bob
Adobe WAS Scripting
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines