Is it possible to get a document descriptor for a document other than app.activeDocument?
For the active document I just use:
Code: Select allvar ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
desc = executeActionGet(ref);
My intermediate goal is to be able to iterate through all the open documents and retrieve the DocI (document ID) for each one without having to make each document active.
TIA,
Brent
Document descriptor for non-active document?
-
Paul MR
Document descriptor for non-active document?
Please try this...
Code: Select allalert(getDocIds());
function getDocIds(){
var IDs = new Array();
var count = app.documents.length;
for(var a =1; a<count+1;a++){
var ref = new ActionReference();
ref.putIndex( charIDToTypeID( "Dcmn" ), a);
var desc = executeActionGet(ref);
IDs.push(desc.getInteger (stringIDToTypeID('documentID')));
}
return IDs;
}
Code: Select allalert(getDocIds());
function getDocIds(){
var IDs = new Array();
var count = app.documents.length;
for(var a =1; a<count+1;a++){
var ref = new ActionReference();
ref.putIndex( charIDToTypeID( "Dcmn" ), a);
var desc = executeActionGet(ref);
IDs.push(desc.getInteger (stringIDToTypeID('documentID')));
}
return IDs;
}
-
bdeshazer
Document descriptor for non-active document?
Thanks Paul, that does indeed work.
What is the advantage/reason for using:
Code: Select alldesc.getInteger(stringIDToTypeID('documentID'))
instead of:
Code: Select alldesc.getInteger(charIDToTypeID('DocI'))
I'm assuming that this is one of the stringids that "maps" to the charid because they both return identical results. Personal preference to use the "new" stringid?
Also, is it possible to directly make a document the active document by using it's ID?
I think once I find the doc desc that has the correct docid I can get the doc index from the same descriptor and then use :
Code: Select allapp.activeDocument=app.documents[docindex];
to do this, but just trying to save a couple steps if it's possible.
Either way you've gotten me over the hurdle, thanks again!
What is the advantage/reason for using:
Code: Select alldesc.getInteger(stringIDToTypeID('documentID'))
instead of:
Code: Select alldesc.getInteger(charIDToTypeID('DocI'))
I'm assuming that this is one of the stringids that "maps" to the charid because they both return identical results. Personal preference to use the "new" stringid?
Also, is it possible to directly make a document the active document by using it's ID?
I think once I find the doc desc that has the correct docid I can get the doc index from the same descriptor and then use :
Code: Select allapp.activeDocument=app.documents[docindex];
to do this, but just trying to save a couple steps if it's possible.
Either way you've gotten me over the hurdle, thanks again!
-
Paul MR
Document descriptor for non-active document?
Like you say it's just preference using charid or stringid.
To select the document by it's ID you can use...
Code: Select allfunction selectDocById(ID) {
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID('Dcmn'), ID);
var desc = new ActionDescriptor();
desc.putReference(charIDToTypeID('null'), ref);
executeAction(charIDToTypeID('slct'), desc, DialogModes.NO);
}
To select the document by it's ID you can use...
Code: Select allfunction selectDocById(ID) {
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID('Dcmn'), ID);
var desc = new ActionDescriptor();
desc.putReference(charIDToTypeID('null'), ref);
executeAction(charIDToTypeID('slct'), desc, DialogModes.NO);
}
-
bdeshazer
Document descriptor for non-active document?
I actually tried modifying the script-listener code created by selecting a document from the Window menu and then switching the "putOffset" relative value to "putIdentifier" (found putIdentifier in the Photoshop Javascript Reference pdf), but it didn't work... Looking at your code I thought "that's exactly what I tried!", and sure enough I just tried again and it worked so I must have made a typo somewhere in my first attempt!
Hugely grateful, thank you once again!
Hugely grateful, thank you once again!