How to move activeDocument's position in app.documents[]
Hello,
Is there a way to move the current document's position in the app.documents array? I've got this function that will transfer part of an image's name (in this case an ID number) from one to the other. The way I've got it set up is that the user has to have at least one image open containing the ID number they want to extract and then they run the script on another image where they want the ID number to go in to. (If that makes sense?)
function connectOu() {
if (app.documents.length <= 1){
alert ("Oops! \nThere needs to be at least one other image open with the PID number you want this transferred to.")
} else {
var originalPid = activeDocument.name
var originalPath = activeDocument.path
var originalLength = activeDocument.name.length
var originalType = originalPid.substring(originalLength - 6,originalLength - 4)
var whatType = prompt ('What type of image should this be?', originalType)
if (whatType === null) {
} else {
activeDocument.save()
activeDocument.close()
var fileRef = new File(originalPath + "/" + originalPid)
var docRef = app.open (fileRef)
activeDocument = app.documents[0]
var newPid = activeDocument.name.substring(0,6)
var newPath = activeDocument.path
var middlePart = activeDocument.name.substring(6, activeDocument.name.length - 6)
activeDocument = documents.getByName(originalPid)
var saveFile = new File(newPath+ "/" + newPid + middlePart + whatType + ".tif");
activeDocument.saveAs(saveFile, TiffSaveOptions,false,Extension.LOWERCASE);
}
}
}
Right now the script closes the activeDocument and reopens it so that it is always the last one in the array due to the fact that the script targets the first image in the array for the extraction. Doing it this way means the script is a little slow and I'd love to speed it up by simply moving the activeDocument's position instead of opening and closing it.
I appreciate any help I can get!
Thanks.