3 Replies Latest reply on Jun 13, 2011 11:59 AM by divinewind

    Placing Library Assets & Grouping for Resize - NEED HELP

    divinewind

      Hey there community,

       

      normally I wouldn't need to ask for help but this one is stumbling me beyond no end.

       

      I am building a script that receives the amount of spot colours in a job from sales via XML file and automatically put the swatches for the job on the proof 1 under the next and resized in a box.

       

      We have all the swatches in an Indesign Library file and I will have the colours used going through a loop and adding the proper swatch from the library onto the page 1 by 1 underneath each other.

       

      The trouble I am having is adding each placed asset into a group with the previously added library item so that I can select the group and resize it proportionally to fit in a specific area.

       

      Here is a mockup of the proposed code (with sensitive information stripped):

       

       

      myLibPath = "library location here";

      myLibrary = app.open(myLibPath);

       

       

      //starting location for swatches to appear on page

       

      var x = 5.2503;

      var y = 1.2913;

       

       

      //loop starts going through all the colours from an xml file and places each one

       

      **loop start here

           t=app.libraries.item("library name here").assets.item("itemname").placeAsset(app.activeDocument);

           t[0].move([x,y+.20]);  //the swatches are placed .20 inches lower than the previous one until finished

      **loop ends here

       

      What would I put in the loop to add the currently placing item into a group and then after the loop is done resize the entire group proportionally to say 3 inches high?

       

      ive tried with some digging throughout this forum for a solution and got this, but it just doesnt want to work.

       

      g=myPage.groups.add(t);  (of course myPage was defined earlier)

       

      Hopefully you geniuses can help me.
      Thanks
      Divine

        • 1. Re: Placing Library Assets & Grouping for Resize - NEED HELP
          John Hawkinson Level 5

          Hi, Divine:

           

          You haven't explained what goes wrong when you try your code. That would be helpful information.

           

          Anyhow, it looks like this strategy:

           

          // **loop start here
            t=app.libraries.item("library name here").
              assets.item("itemname").
              placeAsset(app.activeDocument);
            //the swatches are placed .20 inches lower than the previous
            //one until finished
            t[0].move([x,y+.20]);
          // **loop ends here
          g=myPage.groups.add(t);  (of course myPage was defined earlier)
          

           

          Isn't quite going to work. Because:

          1. You don't increment y each time.
          2. You are going to make the items in t a group, but t only contains the last placed asset, not all of them.

           

          So I think you want something like this:

           

          var allt = [];
          // **loop start here
            t=app.libraries.item("library name here").
              assets.item("itemname").
              placeAsset(app.activeDocument);
            allt.push(t[0]);
            //the swatches are placed .20 inches lower than the previous
            //one until finished
            t[0].move([x,y]);
            y += 0.20;
          // **loop ends here
          g=myPage.groups.add(t);  (of course myPage was defined earlier)
          


          Though perhaps you'll have to do something fancier if there are multiple  items in the asset, since t[0] only gets you the first one.

          1 person found this helpful
          • 2. Re: Placing Library Assets & Grouping for Resize - NEED HELP
            anabasa@hotmail.com

            I'm not entirely sure of this answer but some part of it might come handy (not sure I completelly understood the question anyway).

            How about asigning a tag sequenced tag to each asset and make selection of all the assets, then group?

             

            As said, just an idea... Hope it helps

            • 3. Re: Placing Library Assets & Grouping for Resize - NEED HELP
              divinewind Level 1

              Thanks John, your suggestion worked like a charm and the grouping that was giving me problems worked flawlessly.

               

              Now just to figure out how to scale the group proportionally and I'm gold!

               

              Thanks once again!