7 Replies Latest reply on Jul 23, 2014 6:45 AM by Teetan VK

    Paste in place to next Master unfunction, can you fix it?

    Teetan VK Level 1

      Hi, everyone

       

      I got this script, which copy from:

       

      Paste In Place to Specify Master Page

       

      I change it into:

       

      var myDialog = app.dialogs.add({name:"Copy Select item to next Master",canCancel:true});
      with(myDialog){
          with(dialogColumns.add()){
          staticTexts.add({staticLabel:"Select a Master you want to copy to"});
              with(dialogRows.add()){
                 var mySelection = dropdowns.add({stringList:["Master A", "Master B","Master C", "Master D", "Master E","Master F", "Master G"], selectedIndex:0});
             }
         }
      }
      if (myDialog.show() == true)
         

      function main(){
        if("Copy to next Master");
            copy_to_next_master(); 
          }
      function copy_to_next_master() { 
          if (mySelection.selectedIndex == 0){
      var nSel = app.selection.length;   
           
      for ( var i = 1; i < app.documents.length; i++) {   
              var nextDoc = app.documents[i];   
              if (!nSel) { alert( "Nothing selected!" ); exit(); } 
              for ( var n = 0; n < nSel; n++ ) { 
                  var curSel = app.selection[n]; 
                  curSel.duplicate( nextDoc.masterSpreads[0] ); 
              } 
      }
      }
      alert("Done.\rWhat you select are pasted in place to next documents' Master  A");
      }
          if (mySelection.selectedIndex == 1){
      var nSel = app.selection.length;   
           
      for ( var i = 1; i < app.documents.length; i++) {   
              var nextDoc = app.documents[i];   
              if (!nSel) { alert( "Nothing selected!" ); exit(); } 
              for ( var n = 0; n < nSel; n++ ) { 
                  var curSel = app.selection[n]; 
                  curSel.duplicate( nextDoc.masterSpreads[1] ); 
              } 
      }
      alert("Done.\rWhat you select are pasted in place to next documents' Master  B");
      }

          if (mySelection.selectedIndex == 1){
      var nSel = app.selection.length;   
           
      for ( var i = 1; i < app.documents.length; i++) {   
              var nextDoc = app.documents[i];   
              if (!nSel) { alert( "Nothing selected!" ); exit(); } 
              for ( var n = 0; n < nSel; n++ ) { 
                  var curSel = app.selection[n]; 
                  curSel.duplicate( nextDoc.masterSpreads[2] ); 
              } 
      }
      alert("Done.\rWhat you select are pasted in place to next documents' Master  C");
      }

          if (mySelection.selectedIndex == 1){
      var nSel = app.selection.length;   
           
      for ( var i = 1; i < app.documents.length; i++) {   
              var nextDoc = app.documents[i];   
              if (!nSel) { alert( "Nothing selected!" ); exit(); } 
              for ( var n = 0; n < nSel; n++ ) { 
                  var curSel = app.selection[n]; 
                  curSel.duplicate( nextDoc.masterSpreads[3] ); 
              } 
      }
      alert("Done.\rWhat you select are pasted in place to next documents' Master  D");
      }

          if (mySelection.selectedIndex == 1){
      var nSel = app.selection.length;   
           
      for ( var i = 1; i < app.documents.length; i++) {   
              var nextDoc = app.documents[i];   
              if (!nSel) { alert( "Nothing selected!" ); exit(); } 
              for ( var n = 0; n < nSel; n++ ) { 
                  var curSel = app.selection[n]; 
                  curSel.duplicate( nextDoc.masterSpreads[4] ); 
              } 
      }
      alert("Done.\rWhat you select are pasted in place to next documents' Master  E");
      }

          if (mySelection.selectedIndex == 1){
      var nSel = app.selection.length;   
           
      for ( var i = 1; i < app.documents.length; i++) {   
              var nextDoc = app.documents[i];   
              if (!nSel) { alert( "Nothing selected!" ); exit(); } 
              for ( var n = 0; n < nSel; n++ ) { 
                  var curSel = app.selection[n]; 
                  curSel.duplicate( nextDoc.masterSpreads[5] ); 
              } 
      }
      alert("Done.\rWhat you select are pasted in place to next documents' Master  F");
      }

          if (mySelection.selectedIndex == 1){
      var nSel = app.selection.length;   
           
      for ( var i = 1; i < app.documents.length; i++) {   
              var nextDoc = app.documents[i];   
              if (!nSel) { alert( "Nothing selected!" ); exit(); } 
              for ( var n = 0; n < nSel; n++ ) { 
                  var curSel = app.selection[n]; 
                  curSel.duplicate( nextDoc.masterSpreads[6] ); 
              } 
      }
      alert("Done.\rWhat you select are pasted in place to next documents' Master G");
      }

       

       

      but unfunction, can you fix it?

       

      thanks

       

      Teetan

        • 1. Re: Paste in place to next Master unfunction, can you fix it?
          Chinnadk Level 4

          Hi Teetan

           

          Try this, it will ask you to select a master of the current document, if any of the other opened document master page name matches with the selected master name, then it will copy all the elements from selected master to the other opened documents master page.

           

          var doc =app.activeDocument, 
              masters = doc.masterSpreads,
              masternames = [],
              myDialog = app.dialogs.add({name:"Copy Select item to next Master",canCancel:true});
              with(myDialog)
              {
                  with(dialogColumns.add())
                  {
                      staticTexts.add({staticLabel:"Select a Master you want to copy to"});
                      with(dialogRows.add())
                      {
                          for(var i=0;i<masters.length;i++)
                          {
                                  masternames.push(masters[i].name);
                              }
                          var mySelection = dropdowns.add({stringList:masternames, selectedIndex:0});
                      }
                  }
              }
              myDialog.show();
          var selectedmaster = mySelection.stringList[mySelection.selectedIndex],
              allItems = doc.masterSpreads.item(selectedmaster).pageItems;
          for(var i =1;i<app.documents.length;i++)
          {
                  for(var j=0;j<allItems.length;j++)
                  {
                          allItems[j].duplicate(app.documents[i].masterSpreads.item(selectedmaster))
                      }
              }
          

           

          Regards,

          Chinna

          • 2. Re: Paste in place to next Master unfunction, can you fix it?
            Teetan VK Level 1

            Hi, Chinna

             

            thank you for your help,

             

            but the script only can paste in place to next master A, not work in B,C,D....

             

            why?

             

            Regard

             

            VK

            • 3. Re: Re: Paste in place to next Master unfunction, can you fix it?
              Chinnadk Level 4

              Try now.

               

              var doc =app.activeDocument, 
                  masters = doc.masterSpreads, 
                  masternames = [], 
                  myDialog = app.dialogs.add({name:"Copy Select item to next Master",canCancel:true}); 
                  with(myDialog) 
                  { 
                      with(dialogColumns.add()) 
                      { 
                          staticTexts.add({staticLabel:"Select a Master you want to copy to"}); 
                          with(dialogRows.add()) 
                          { 
                              for(var i=0;i<masters.length;i++) 
                              { 
                                      masternames.push(masters[i].name); 
                                  } 
                              var mySelection = dropdowns.add({stringList:masternames, selectedIndex:0}); 
                          } 
                      } 
                  } 
                  myDialog.show(); 
              var selectedmaster = mySelection.stringList[mySelection.selectedIndex], 
                  allItems = doc.masterSpreads.item(selectedmaster).pageItems; 
              for(var i =1;i<app.documents.length;i++) 
              { 
                      for(var k =0;k<app.documents[i].masterSpreads.length;k++)
                      {
                              for(var j=0;j<allItems.length;j++) 
                              { 
                                  allItems[j].duplicate(app.documents[i].masterSpreads[k]) 
                                  }
                          }
                       
                  }
              

               

              Regards,

              Chinna

              • 4. Re: Paste in place to next Master unfunction, can you fix it?
                Teetan VK Level 1

                Hi, Chinna

                 

                I try it three times

                 

                but still not working

                 

                vk

                • 5. Re: Re: Paste in place to next Master unfunction, can you fix it?
                  Jump_Over Level 5

                  Hi,

                   

                  Modifying your code - notice that function main() suppose to be

                  1. defined and

                  2. called

                   

                  Compare it to this code:

                  #target  indesign
                  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});
                        }
                    }
                  }
                  main();
                  
                  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");
                  }
                  

                   

                  Jarek

                  • 6. Re: Paste in place to next Master unfunction, can you fix it?
                    Teetan VK Level 1

                    Thank you Jarek

                     

                    I think I have learn how to call function in Java

                     

                    thank so much

                     

                    regard

                     

                    VK

                    • 7. Re: Paste in place to next Master unfunction, can you fix it?
                      Teetan VK Level 1

                      Hi, Chinna

                       

                      Thank you for your help, appreciate.

                       

                      I finally get What I want.

                       

                      But I still remain another script need fix it, do you have anything idea to fix?

                       

                      How can use radiobuttonControls to join three scripts together?

                       

                      as same as this script, I want joint the script together, but I don't know how to call function

                       

                      thanks

                       

                      Regard

                       

                      VK