8 Replies Latest reply on Nov 23, 2010 1:30 AM by tansk02

    My Function is not working (Please help)

    tansk02 Level 1

       

      var myDialog = new Window('dialog',"MyTool");

      buildWindow();

      myDialog.show();

      function buildWindow(){

      myDialog.alignChildren = "left";

      // Properties for myReportFolder

      myDialog.preferredSize.width=300

      var myReportFolder=myDialog.add('panel',undefined,"Choose folder to save report:", {borderStyle:'raised'});

      myReportFolder.orientation="row"

      // Properties for mySelectedFolder

      // var mySelectedFolder = myReportFolder.add('group',undefined);

      // Properties for mySelectedPath

      var mySelectedPath = myReportFolder.add('edittext',undefined,"~/Report path");

      mySelectedPath.preferredSize.width = 275;

      // Properties for myBrowseFolder

      var myBrowseFolder = myReportFolder.add('button',undefined,"Choose");

      myBrowseFolder.onClick = function ()

      {

      var myfilePath=Folder.selectDialog ("Choose a Report Folder");

      if(myfilePath != null)mySelectedPath.text=myfilePath.fsName;

      }

      var myPanel1 = myDialog.add('statictext',undefined,"Select Document Language:");

      var theLanguages = app.languagesWithVendors.everyItem().name;

      // Properties for myPanel1.dropDownList

      var dropDownList = myDialog.add('dropdownlist',undefined,undefined,{items:theLanguages}) ;

      dropDownList.selection = 1;

      // Properties for myChoice

      var myChoice = myDialog.add('panel',undefined,"Select your option", {borderStyle:'raised'});

      myChoice.alignChildren = "left";

      // Properties for searchDoubleSpace

      // Properties for searchWrongLanguage

      var searchWrongLanguage = myChoice.add('checkbox',undefined,"Find Languages other than above selected Language");

      searchWrongLanguage.value = false;

      var searchDoubleSpace = myChoice.add('checkbox',undefined,"Find Double Spaces");

      searchDoubleSpace.value = false;

      var unusedParaStyle = myChoice.add('checkbox',undefined,"Find Unused Paragraph Styles");

      unusedParaStyle.value = false;

      var myBleed = myChoice.add('checkbox',undefined,"Check Bleed Value");

      myBleed.value = false;

      // Properties for myDialog.myPanel3

      var myPanel4= myDialog.add('panel',undefined,undefined, {borderStyle:'raised'});

      // Properties for myPanel4.closeButton

      myPanel4.orientation="row"

      myPanel4.closeButton = myPanel4.add('button',undefined,"Close",{name:'cancel'});//tan:add name cancel

      // Properties for myPanel4.goButton

      myPanel4.goButton = myPanel4.add('button',undefined,"RUN",{name:'ok'});//tan: add name ok

      myPanel4.goButton.onClick = function (){

      //Bleed

      var myDocName=app.activeDocument.name;

      var myFilePath1=mySelectedPath.text + "/" + myDocName + ".txt";

      var myTextFile = new File(myFilePath1);

      if ( myTextFile.exists )

      {

      myTextFile.remove(myTextFile);

      }

      flag=false;

      if (myBleed.value == true){//running succesfully

      myDoc=app.activeDocument.documentPreferences

      if ((myDoc.documentBleedTopOffset)!=9){

      write("Document TOP Bleed is not correct "+myDoc.documentBleedTopOffset);

      }

      if ((myDoc.documentBleedBottomOffset)!=9){

      write("Document BOTTOM Bleed is not correct "+myDoc.documentBleedBottomOffset);

      }

      if ((myDoc.documentBleedInsideOrLeftOffset)!=9){

      write("Document INSIDE/LEFT Bleed is not correct "+myDoc.documentBleedInsideOrLeftOffset);

      }

      if ((myDoc.documentBleedOutsideOrRightOffset)!=9){

      write("Document OUTSIDE/RIGHT Bleed is not correct "+myDoc.documentBleedOutsideOrRightOffset);

      }

      }//close if

      //Unused Paragraph style

      if (unusedParaStyle.value == true){

      var myDoc = app.activeDocument;

      var myParStyles = myDoc.paragraphStyles;

      for (j = myParStyles.length-1; j >= 2; j-- ) {

      removeUnusedParaStyle(myParStyles[j]);

      }

      function removeUnusedParaStyle(myPaStyle) {

      app.findTextPreferences = NothingEnum.nothing;

      app.changeTextPreferences = NothingEnum.nothing;

      app.findTextPreferences.appliedParagraphStyle = myPaStyle;

      var myFoundStyles = myDoc.findText();

      if (myFoundStyles == 0) {

      write(myPaStyle.name);

      }

      app.findTextPreferences = NothingEnum.nothing;

      app.changeTextPreferences = NothingEnum.nothing;

      }

      }//close if

      //Search for Double Spaces

      if (searchDoubleSpace.value == true){

      app.findGrepPreferences = NothingEnum.nothing;

      app.changeGrepPreferences = NothingEnum.nothing;

      app.findGrepPreferences.findWhat = " ";

      var result = Number(app.activeDocument.findGrep().length);

      if (result>=1){

      write("Double space found in this document " + result);

      }

      }//close if

      //Search for Wrong Language

      if (searchWrongLanguage.value == true){

      //working

      langList = [];

      for (s=0; s<app.activeDocument.stories.length; s++)

      {

      tr = app.activeDocument.stories[s].textStyleRanges;

      for (t=0; t<tr.length; t++)

      {

      if (!inArray (langList, tr[t].appliedLanguage.name))

      langList.push (tr[t].appliedLanguage.name);

      }

      }

      write ("Number of languages: "+langList.length+"\r(And they are: "+langList.join(", ")+")");

      function inArray (arr, items)

      {

      var check;

      for (check=0; check<arr.length; check++)

      if (arr[check] == items)

      return true;

      return false;

      }

      }//close if

      else (searchWrongLanguage.value == false){

      }//close else if

      }//close onClick function

      }//end buildWindow

      //*****Browse Report Folder and Writing file

      function write(text){

      var myDocument=app.activeDocument;

      var myFilePath1=myDocument.filePath + "/" + "myDocument_Report" + ".txt";

      var myTextFile = new File(myFilePath1);

      if ( myTextFile.exists )

      {

      myTextFile.open("e");

      myTextFile.seek(0, 2);

      }

      else {

      myTextFile.open("w");

      }

      myTextFile.write(text+"\r");

      myTextFile.close()

      myTextFile.execute()

      }

      Hi All,

       

      I have created below script. But there is some problem which I am unable to find.

       

      My two check boxes 1) Find double Spaces and 2) Find Unused Paragraph Styles is not running in this script. When I run this script on ESTK it gives error "Cannot handle the request because a modal dialog or alert is active."

       

      But every function is working fine as a single script. Please check.

       

      Thanks in advance for your effort on this.

      Tan

       

      See my script code below. Its messy but working.