My file has more than 300 pages with 350 images when i run the script first 50 pages its taking 15 mins after that its taking 3 hours to complete the entire document Can you please suggest how to optimize the code. function placeElement(){ var myRuleSet = new Array (new checkBoxText); with (myDoc){ var elements = xmlElements; __processRuleSet(elements.item(0), myRuleSet); } function checkBoxText(){ this.name = "checkBoxText"; this.xpath = "//book/*" ; this.apply = function (myElement, myRuleProcessor){ with (myElement){ if (!myElement.markupTag.name.match(/Place-Holder/)){ try{ if (myElement.markupTag.name == 'Sections'){ if ( count != -1){ var midPage = myDoc.pages[-1]; myPg = myDoc.pages.add( LocationOptions.AFTER, midPage ); myPg.appliedMaster = myDoc.masterSpreads.item('Adv-Photo'); overridesObjects(myPg); myframe = myPg.textFrames.item(myElement.markupTag.name); myElement.placeXML(myframe); try {myframe.paragraphs[0].appliedParagraphStyle = myDoc.paragraphStyles.item('Photo');} catch(e){} if (myframe.parentStory.overflows == true){ myframe.fit(FitOptions.frameToContent); } // try{ myElement.xmlElements[0].xmlElements[1].xmlElements[2].placeXML(myPg.rectangles[0]); } catch(e){} count ++; } else { var myPg = myDoc.pages[-1]; myPg.appliedMaster = myDoc.masterSpreads.item('Adv-Photo'); overridesObjects(myPg) try { try{ myframe = myPg.textFrames.item(myElement.markupTag.name); myElement.placeXML(myframe); if (myframe.parentStory.overflows == true){ myframe.fit(FitOptions.frameToContent); } } catch(e){} } catch(e){} count ++; } } if (myElement.markupTag.name == 'BkInfo'){ myDoc.save(); if ( count != -1){ var midPage = myDoc.pages[-1]; for(var k =0; k <midPage.textFrames.length; k++ ){ midPage.textFrames .name = midPage.textFrames .name+'_'+ midPage.name } myPg = myDoc.pages.add( LocationOptions.AFTER, midPage ); myPg.appliedMaster = myDoc.masterSpreads.item('TXT-ThisBookHead1') overridesObjects(myPg) } count ++; } var myPage = myDoc.pages[count] myframe = myPage.textFrames.item(myElement.markupTag.name); if ((xmlElements.nextItem(myElement).isValid) && (myframe.isValid)){ try { mynextframe = myPage.textFrames.item(xmlElements.nextItem(myElement).markupTag.name) mynextframe.label = xmlElements.nextItem(myElement).paragraphs[0].appliedParagraphStyle.name; } catch(e){} myElement.placeXML (myframe); if (myframe.label != ""){ try {myframe.paragraphs[0].appliedParagraphStyle = myDoc.paragraphStyles.item(myframe.label);} catch(e){} } if (myElement.markupTag.name == 'BkTOC'){ applystyle('ChapterHead', myframe, myPage) } myframe.name = myframe.name + '_boxplaced' } }//try catch (e){ } } }//with myElement return true; };//apply function }//check box text function }//box element name function
... View more