Extendscript: finding book component with specific string in filename
Dear fellows,
I'm trying to put together a script that performs the following on an open FM book:
1. Creates an array of book components.
2. In the array, finds the book component with a file name that includes the word 'Carrier' and (nice to have: doesn't include the word "Internal").
3. When found, opens the book component that includes the word 'Carrier' and (nice to have: doesn't include the word "Internal").
4. Imports the conditional/variable settings from the 'Carrier' to the rest if the book components.
5. Closes all book components.
Here is my code snippet.
#target framemaker
var book = app.ActiveBook;
var bookComp = book.FirstComponentInBook;
book.IsOnScreen = 1;
importCarrier();
function importCarrier() {
var carrier = "Carrier";
var compAr = [];
if (book.ObjectValid()) {
while (bookComp.ObjectValid()) {
compAr.push(bookComp);
bookComp = bookComp.NextBookComponentInDFSOrder;
}
for (var i = 0; i < compAr[i].length; i++) {
alert(compAr[i].Name);
var tMatch = compAr[i].Name.match(carrier);
if (tMatch == carrier){
var CarrierFileName = compAr[i].Name;
}
}
var openParams = getOpenPrefs();
var openReturnParams = new PropVals();
var openCarrierFM = Open(CarrierFileName, openParams, openReturnParams);
if (openCarrierFM.ObjectValid()) {
var targetDoc = Open(bookComp.Name, openParams, openReturnParams);
if (targetDoc.ObjectValid()) {
targetDoc.SimpleImportFormats(openCarrierFM, Constants.FF_UFF_COND | Constants.FF_UFF_VAR);
targetDoc.SimpleSave(targetDoc.Name, false);
targetDoc.Close(1);
}
else {
alert("Cannot open " + targetDoc.Name); }
targetDoc = bookComp.NextBookComponentInDFSOrder;
}
openCarrierFM.Close(1);
}
}
function getOpenPrefs() {
var params, i;
params = GetOpenDefaultParams();
i = GetPropIndex(params, Constants.FS_RefFileNotFound);
params[i].propVal.ival = Constants.FV_AllowAllRefFilesUnFindable;
i = GetPropIndex(params, Constants.FS_FileIsOldVersion);
params[i].propVal.ival = Constants.FV_DoOK;
i = GetPropIndex(params, Constants.FS_FontChangedMetric);
params[i].propVal.ival = Constants.FV_DoOK;
i = GetPropIndex(params, Constants.FS_FontNotFoundInCatalog);
params[i].propVal.ival = Constants.FV_DoOK;
i = GetPropIndex(params, Constants.FS_FontNotFoundInDoc);
params[i].propVal.ival = Constants.FV_DoOK;
i = GetPropIndex(params, Constants.FS_LockCantBeReset);
params[i].propVal.ival = Constants.FV_DoOK;
i = GetPropIndex(params, Constants.FS_FileIsInUse);
params[i].propVal.ival = Constants.FV_OpenViewOnly;
return (params);
}Issues:
1. The code doesn't identify the array members' file names.
2. Doesn't recognize openCarrierFM.Close(1); as a function.
Will appreciate your inputs. Thank you in advance!
