1 Reply Latest reply on Feb 25, 2014 12:37 PM by julien_anquetil

    Place X asset on each Page JS

    julien_anquetil

      Hi,

       

      I'm working with assets from library and a xml. My goal is to read an XML file and count number of element.
      Then get nb element and place 6 assets by page.

       

       

      Before trying do it with xml value, I try to do it with Fixed Value.

       

      var myDoc = app.activeDocument;

      var myPages = myDoc.pages;

      var libraryFilePath=new File("/Users/Mitchum/Desktop/catalogue2015/ressources/Library.indl");

      app.open(File(libraryFilePath));

      myAsset = app.libraries[0].assets.item("test"); // name of the asset

      for (var pg =1; myPages.length>pg; pg++)

      {

          var myDoc = app.activeDocument;

          var myPages = myDoc.pages;

          if (myPages[pg].side==PageSideOptions.RIGHT_HAND){//Page de droite

               if (pg ==0){//check right firstpage

                  var myObj = myAsset.placeAsset(app.documents.item(0))[0];; //first place library in first page

                  myObj.move (myPages[pg]);

                  myObj.move ( [12, 15] );//change ur x.y coodinate as per ur requirement

                  }

              else{

                  var myObj = myAsset.placeAsset(app.documents.item(0))[0];; //first place library in first page

                  myObj.move (myPages[pg]);

                  myObj.move ( [210, 30] )

                  }

          }

          if(myPages[pg].side==PageSideOptions.LEFT_HAND){

                  var myObj = myAsset.placeAsset(app.documents.item(0))[0]; //first place library in first page

                   }

          }

      }

       

       

      With some search on this forum I got this to place One asset by page.
      But I'm pretty lost to know how to "repeat" the process.
      I try to do a loop like

       

      for (var i = 0;i<7;i++){

                         alert(i);   

                          //premier element

                          if(i==0){

                               var myObj = myAsset.placeAsset(app.documents.item(i))[0]; //first place library in first page

                              myObj.move (myPages[pg]);

                              myObj.move ( [10, 30] );//change ur x.y coodinate as per ur requirement

                          }

       

                           else if(i==1){

                               var myObj = myAsset.placeAsset(app.documents.item(i))[0]; //first place library in first page

                              myObj.move (myPages[pg]);

                              myObj.move ( [103, 30] );//change ur x.y coodinate as per ur requirement

                          }

                          else if(i==2){

                              var myObj = myAsset.placeAsset(app.documents.item(i))[0]; //first place library in first page

                              myObj.move (myPages[pg]);

                              myObj.move ( [10, 110] );//change ur x.y coodinate as per ur requirement

                          }

                           else if(i==3){

                               var myObj = myAsset.placeAsset(app.documents.item(i))[0]; //first place library in first page

                              myObj.move (myPages[pg]);

                              myObj.move ( [103, 110] );//change ur x.y coodinate as per ur requirement

                          }

                            else if(i==4){

                               var myObj = myAsset.placeAsset(app.documents.item(i))[0]; //first place library in first page

                              myObj.move (myPages[pg]);

                              myObj.move ( [10, 190] );//change ur x.y coodinate as per ur requirement

                          }

                            else if(i==5){

                               var myObj = myAsset.placeAsset(app.documents.item(i))[0]; //first place library in first page

                              myObj.move (myPages[pg]);

                              myObj.move ( [103, 190] );//change ur x.y coodinate as per ur requirement

                          }

       

       

                   }

       

       

       

      But it's working for 3 element but fail on the 4th with an error like "30477 error, incorrect value for parameter "on" of methode "placeasset" Document or Text waiting but nothing get (I translate error message cause I'm on FR indesign)

       

      By the way, I think there is a better way to do this like all my elseif no ?

       

      Thanks for your Help !

        • 1. Re: Place X asset on each Page JS
          julien_anquetil Level 1

          Wow I didn't see I faill in app.documents.item(i).

          Like that it's working :

           for (var i = 0;i<7;i++){
                            // alert(app.documents.item(0));    
                              //premier element
                              if(i==0){
                                   var myObj = myAsset.placeAsset(app.documents.item(0))[0]; //first place library in first page
                                  myObj.move (myPages[pg]);
                                  myObj.move ( [10, 30] );//change ur x.y coodinate as per ur requirement
                              }
                               
                               else if(i==1){
                                   var myObj = myAsset.placeAsset(app.documents.item(0))[0]; //first place library in first page
                                  myObj.move (myPages[pg]);
                                  myObj.move ( [103, 30] );//change ur x.y coodinate as per ur requirement
                              }
                              else if(i==2){
                                  var myObj = myAsset.placeAsset(app.documents.item(0))[0]; //first place library in first page
                                  myObj.move (myPages[pg]);
                                  myObj.move ( [10, 110] );//change ur x.y coodinate as per ur requirement
                              }
                               else if(i==3){
                                   var myObj = myAsset.placeAsset(app.documents.item(0))[0]; //first place library in first page
                                  myObj.move (myPages[pg]);
                                  myObj.move ( [103, 110] );//change ur x.y coodinate as per ur requirement
                              }
                                else if(i==4){
                                   var myObj = myAsset.placeAsset(app.documents.item(0))[0]; //first place library in first page
                                  myObj.move (myPages[pg]);
                                  myObj.move ( [10, 190] );//change ur x.y coodinate as per ur requirement
                              }
                                else if(i==5){
                                   var myObj = myAsset.placeAsset(app.documents.item(0))[0]; //first place library in first page
                                  myObj.move (myPages[pg]);
                                  myObj.move ( [103, 190] );//change ur x.y coodinate as per ur requirement
                              }