Skip to main content
Participant
September 1, 2022
Question

insufficient memory to display the dialog box

  • September 1, 2022
  • 1 reply
  • 176 views

I have a script to open documents, make a modification, save and close the document but when reaching a large number of documents an alert pops up:

 

"Insufficient memory to display the dialog box. Close one or more windows and try again"

 

But at this point all the documents are closed and I can't open any more.

Does anyone know how to clear the memory or expand the memory.

This topic has been closed for replies.

1 reply

K.Daube
Community Expert
Community Expert
September 2, 2022

Your script may create a recursion: for each document create a new dialogue.

Can you post the code to verify this assumption?

Participant
September 5, 2022

Of course, this is just the main part of the script:
everything starts in the main method (this last)

 

var constantsToOpen = [
    {ask: Constants.FS_AlertUserAboutFailure, select: false},
    {ask: Constants.FS_DisallowMIF, select: false},
    {ask: Constants.FS_DisallowXml, select: false},
    {ask: Constants.FS_FileIsInUse, select: Constants.FV_ResetLockAndContinue},
    {ask: Constants.FS_BookIsInUse, select: Constants.FV_ResetLockAndContinue},
    {ask: Constants.FS_LockCantBeReset, select: Constants.FV_DoOK},
    {ask: Constants.FS_FileIsOldVersion, select: Constants.FV_DoOK},
    {ask: Constants.FS_FontChangedMetric, select: Constants.FV_DoOK},
    {ask: Constants.FS_FontNotFoundInCatalog, select: Constants.FV_DoOK},
    {ask: Constants.FS_FontNotFoundInDoc, select: Constants.FV_DoOK},
    {ask: Constants.FS_LanguageNotAvailable, select: Constants.FV_DoOK},
    {ask: Constants.FS_OpenAsType, select: Constants.FV_AUTORECOGNIZE},
    {ask: Constants.FS_UpdateTextReferences, select: Constants.FV_DoNo},
    {ask: Constants.FS_UpdateXRefs, select: Constants.FV_DoNo},
    {ask: Constants.FS_UseRecoverFile, select: Constants.FV_DoNo},
    {ask: Constants.FS_UseAutoSaveFile, select: Constants.FV_DoNo},
    {ask: Constants.FS_OpenFileNotWritable, select: Constants.FV_DoOK},
    {ask: Constants.FS_RefFileNotFound, select: Constants.FV_DoOK}
];

var propsToOpen = GetOpenDefaultParams();
var returnp = new PropVals();

function setPropsToOpen() {
    for(var i=0; i < constantsToOpen.length; i++)
    {
        var index = GetPropIndex(propsToOpen, constantsToOpen[i].ask);
        if(index > -1)
            propsToOpen[index].propVal.ival = constantsToOpen[i].select;
    }
}

function OpenFile(path) {
    return Open(path, propsToOpen, returnp);
}

function closeDocument(document) {
    document.Close(Constants.FF_CLOSE_MODIFIED);
}

function saveFile(file) {
    retProps = new PropVals();
    saveProps = GetSaveDefaultParams();
    var index = GetPropIndex(saveProps, Constants.FS_AutoBackupOnSave);
    saveProps[index].propVal.ival = Constants.FV_SaveNoAutoBackup;
    file.Save(file.Name, saveProps, retProps);
}

function setMasterPage(document, plantilla) {
    document.SimpleImportFormats(plantilla, Constants.FF_UFF_PAGE);
    saveFile(document);
}

function fileExist(path) {
    var file = File(path);
    if (file.exists) 
    	return true;
    return false;
}

function getNameWithExtensionPDF(name) {
    return name.replace (/[^\.]+$/, "pdf");
}

function openBookComponents(book) {
    var comp = book.FirstComponentInBook;    
    while(comp.ComponentType == Constants.FV_BK_FILE)
    {
        if (fileExist(comp.Name))
        {            
                var documentOpened = OpenFile(comp.Name);                                
                templateSelected = OpenFile("C:\\Users\\USUARIO\\Documents\\template.fm");
                    if (templateSelected && templateSelected.ObjectValid()) {
                        documentOpened.PDFBookmark = true;
                        documentOpened.DocAcrobatElements = false;
                        setMasterPage(documentOpened, templateSelected);
                    }
                }
                closeDocument(documentOpened);            
        } else return false;
        comp = comp.NextBookComponentInDFSOrder;
    }
}

function saveBookAsPdf (book, name) {
    var params, returnParams, index;
    params = GetSaveDefaultParams ();
    returnParams = new PropVals ();
    index = GetPropIndex (params, Constants.FS_FileType);
    params[index].propVal.ival = Constants.FV_SaveFmtPdf;
	index = GetPropIndex (params, Constants.FS_PDFUseDistiller);
    params[index].propVal.ival = 0;
    index = GetPropIndex(params, Constants.FS_FileIsInUse);
    params[index].propVal.ival = Constants.FV_ResetLockAndContinue;
    book.PDFJobOption = "Standard";
    book.Save (name, params, returnParams);	
    return FA_errno;
}

function openBooks(book) {
    var document = OpenFile(book.fsName);
    if (document.ObjectValid())
    {
        if (openBookComponents(document))
            saveBookAsPdf(document, getNameWithExtensionPDF(document.Name));
        closeDocument(document);
    }
}

function getSubFolders(selectedFolder) {    
     var files = selectedFolder.getFiles("*.book");
     for( var indiceBook=0; indiceBook < files.length; indiceBook++) 
     {
        openBooks(files[indiceBook]);        
    }
    
    var folders = selectedFolder.getFiles(function (f) {return f instanceof Folder;});
    for( var indiceFolder=0; indiceFolder < folders.length; indiceFolder++)
    {
        getSubFolders(folders[indiceFolder]);
    }
}

function main() {
    var selectedFolderTemplateNews = Folder("C:\\Users\\USUARIO\\Documents\\Documents");
    if (selectedFolder) {
        setPropsToOpen();
        getSubFolders(selectedFolder);
    }
}