Answered
Error importing bridge file via listbox:
Hello everyone!
My script gets and adds all the images selected in the bridge to the listbox, and it does something when I click the button, but if I remove some items from the listbox, it doesn't execute on the respective images in the list.
Ex: imag1, imag2 .... if I remove imag1 from the list, it would certainly run something on imag2, but it runs on imag1.
Could someone help me resolve this error?
var ImgConteudo=[];
dlg= new Window("dialog", "My Dialog", {x:0, y:0, width:230, height:360} );
var lbx = dlg.add("listbox", {x:15, y:10, width: 200, height: 200}, ImgConteudo, {multiselect: true});
b1 = dlg.add("button", {x:116, y:317, width: 99, height: 15}, "Remover" );
b2 = dlg.add("button", {x:15, y:317, width: 99, height: 15}, "Process" );
ImgConteudo = GetFilesFromBridge();
for(i=0; i<ImgConteudo.length;i++){
lbx.add("item", decodeURI(ImgConteudo[i].name));
}
b1.onClick = function () {
var sel = lbx.selection[0].index;
for (var i = lbx.selection.length-1; i > -1; i--)
lbx.remove (lbx.selection[i]);
if (sel > lbx.items.length-1)
lbx.selection = lbx.items.length-1;
else lbx.selection = sel;
}
b2.onClick = function () {
dlg.close();
BridgeDocs()
}
dlg.center();
dlg.show();
function BridgeDocs(){
ImgConteudo = GetFilesFromBridge();
for (var i = 0; i < lbx.items.length; i++){
var d1 = new ActionDescriptor();
d1.putPath(app.charIDToTypeID("null"), new File(ImgConteudo[i]));
executeAction(app.charIDToTypeID("Opn "), d1, DialogModes.NO);
alert(ImgConteudo[i]);
}
}
function GetFilesFromBridge() {
function script(){
var fL = app.document.selections;
var tF=[];
for(var a in fL){
if(fL[a].type =='file'){
tF.push(new File(encodeURI(fL[a].spec.fsName)));
}
}
return tF.toSource();
}
var fileList;
var bt = new BridgeTalk();
bt.target = "bridge";
bt.body = "var ftn = " + script.toSource() + "; ftn();";
bt.onResult = function( inBT ) { fileList = eval( inBT.body ); }
bt.onError = function( inBT ) { fileList = new Array(); }
bt.send(8);
bt.pump();
if ( undefined == fileList ) fileList = new Array();
return fileList;
};