4 Replies Latest reply on Jul 29, 2014 7:36 AM by Teetan VK

    How to add an error message to script?

    Teetan VK Level 1

      Hi, every one

       

      I got this script

      function paste in place to next master

       

      I want to add an error message to it, if there was no such thing as master B, C,D,E,F,G

       

      instead of system error.

       

      Teetan

       

       

      var

        myDialog = app.dialogs.add({name:"Copy Selected item(s) to chosen Master",canCancel:true}),

        mStringList = ["Master A", "Master B","Master C", "Master D", "Master E","Master F", "Master G"];

      with(myDialog){

        with(dialogColumns.add()){

        staticTexts.add({staticLabel:"Select a Master you want to copy to"});

        with(dialogRows.add()){

        var mySelection = dropdowns.add({stringList:mStringList, selectedIndex:0});

            }

        }

      }

       

      app.doScript('main()', ScriptLanguage.JAVASCRIPT, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "Paste in place");

      function main(){

        if (!app.documents.length || !app.selection.length)

        {

        alert( "Nothing selected!" );

        exit();

        } 

        if (myDialog.show() == true)

        copy_to_next_master(); 

          }

      function copy_to_next_master() { 

      var

        mChoice = mySelection.selectedIndex,

        mMsg = "Done.\rWhat you select is pasted in place to next documents - " + mStringList[mChoice],

        nSel = app.selection.length,

        mDone = false,

        i,n,nextDoc,curSel;   

       

      for ( i = 1; i < app.documents.length; i++) {   

        nextDoc = app.documents[i];   

        targetMaster = nextDoc.masterSpreads[mChoice];

        if (!targetMaster.isValid) {

        mMsg += "\rCan't detect " + mStringList[mChoice] + " in a doc: " + nextDoc.name;

        continue;

        }

        mDone = true;

        for ( n = 0; n < nSel; n++ ) { 

        curSel = app.selection[n]; 

        curSel.duplicate( nextDoc.masterSpreads[mChoice] ); 

              } 

        }

      mDone ? alert(mMsg) : alert("Nothing copied");

      }