7 Replies Latest reply on May 30, 2012 2:03 AM by Velprakash

    Place figure in pasteboard

    Velprakash

      Hi All,

          I've created a lebrary file named, "Library.indl" file. In that i've two figures named "a", "b". Now i've to place this figures in pasteboard of my document.

      I'm using CS 5.

      My codes are like this:

       

      app.open("C:/Documents and Settings/velprakashk/Desktop/Library.indl");

      lib=app.libraries.item("Library.indl");

      doc=app.activeDocument;

      var img1=lib.assets.item("a");

      var img2=lib.assets.item("b");

      img1.placeAsset(doc);

      img2.placeAsset(doc);

      //I'm placing the figures in document. but i've to place in pasteboard.

       

      Please provide me the right way frnds...

       

      Thanks and regards,

      K.Vel.

        • 1. Re: Place figure in pasteboard
          John Hawkinson Level 5

          placeAsset() returns an array of objects placed.

          Group them, move them, and then ungroup them.

           

          E.g.:

           

          var a1=img1.placeAsset(doc);
          var g1=doc.groups.add(a1);
          g1.move([-100,0]); // or wherever
          g1.ungroup();
          

          etc.

          • 2. Re: Place figure in pasteboard
            Velprakash Level 1

            Hi John Hawkin,

                       First of all, I've to thank you for spent your valuable time for my question...

            I use your example codes.... But it's showing error in the below line.

             

            var g1=doc.groups.add(a1);

            // Invalid Parameter.

             

            Please help...

             

            Vel.

            • 3. Re: Place figure in pasteboard
              Velprakash Level 1

              Hi John Hawkin,

                               Finally i solved the issue... Nw it works fine.

              My codes are,

               

              app.open("C:/Documents and Settings/velprakashk/Desktop/Library.indl");

              lib=app.libraries.item("Library.indl");

              doc=app.activeDocument;

              var img1=lib.assets.item("a");

              var img2=lib.assets.item("b");

              img1.placeAsset(doc);

              img2.placeAsset(doc);

              var xxx=doc.allGraphics.length;

              for(var i=0;i<xxx;i++)

              {

                  var imm=doc.allGraphics[i];

                  var yyy=doc.allGraphics[i].parent.geometricBounds;

                  var gb1=yyy[0];

                  var gb2=yyy[1];

                  var gb3=yyy[2];

                  var gb4=yyy[3];

                  var nb1=gb1;

                  var nb2=gb2+200;

                  var nb3=gb3;

                  var nb4=gb4+200;

                  imm.fit(FitOptions.contentToFrame);

                  app.select(imm.parent);

                  app.selection[0].geometricBounds=[nb1,nb2,nb3,nb4];

                  app.selection[0].fit(FitOptions.contentToFrame);

                  }

               

              Anyway, thanks a lot for your response....

               

              With Regards,

              K.Vel

              • 4. Re: Place figure in pasteboard
                John Hawkinson Level 5

                I'm glad you got it working, but that looks like a horrible solution.

                YOu should really never use the selection if you can avoid it, and it should be sufficient to use the .move() method instead of tinkering with the geometricbounds of the frame and its parent.

                Also, bad things happen if you have existing content in your document and you loop over allGraphics.

                Not to mention if you had more than one page...

                 

                I don't know why you got an Invalid Parameter with my example. Did you in fact set a1 to the return value of .placeAsset()? Was it an array? What was its length?

                • 5. Re: Place figure in pasteboard
                  Velprakash Level 1

                  I really glad to see your response John hawkinson...

                   

                  "a1" is not returning an array. It's returning [Object Rectangle]".

                   

                  Length of "a1" is returning "1"...

                   

                  Thanks and regards,

                  K.Vel


                  • 6. Re: Place figure in pasteboard
                    John Hawkinson Level 5

                    Oh, I see.

                     

                    "a1" is not returning an array. It's returning [Object Rectangle]".

                    Length of "a1" is returning "1"...

                    That may appear to be the case, but it's not actually true. If it has a .length property, it's almost always an Array. You can check with the .constructor property:

                     

                    >> a1

                    [object Oval]

                    >> a1.constructor.name

                    Array

                    >> a1.length

                    1

                    >> a1[0].length

                    Error: Object does not support the property or method 'length'

                    >> a1[0]

                    [object Oval]

                     

                    But that clarifies the problem. You cannot make a group out of a single object. So if you have a single object in the library item, you can move that item by itself. So I suppose the proper form is more like this:

                     

                    var a1=img1.placeAsset(doc);

                    if (a1.length > 1) {
                      var g1=doc.groups.add(a1);
                      g1.move([-100,0]); // or wherever
                      g1.ungroup();

                    } else {

                      a1[0].move([-100,0]); // or wherever

                    }

                    1 person found this helpful
                    • 7. Re: Place figure in pasteboard
                      Velprakash Level 1

                      Hi John Hawkinson,

                                   I'm really glad to appreciate you.......... You're right........ Now it work's fine...

                      Thanks a lot hawkinson...........

                      My script is,

                       

                      var x=app.open("C:/Documents and Settings/velprakashk/Desktop/Library.indl");

                      lib=app.libraries.item("Library.indl");

                      doc=app.activeDocument;

                      var img1=lib.assets.item("a");

                      var img2=lib.assets.item("b");

                      var a1=img1.placeAsset(doc);

                      if (a1.length > 1)

                      {

                          var g1=doc.groups.add(a1);

                          g1.move([-100,0]); // or wherever

                          g1.ungroup();

                          }

                      else

                      {

                          a1[0].move([-200,0]); // or wherever

                          a1[0].fit(FitOptions.contentToFrame);

                          }

                       

                       

                      var b1=img2.placeAsset(doc);

                      if (b1.length > 1)

                      {

                          var g1=doc.groups.add(b1);

                          g1.move([-100,0]); // or wherever

                          g1.ungroup();

                          }

                      else

                      {

                          b1[0].move([-200,200]); // or wherever

                          a1[0].fit(FitOptions.contentToFrame);

                          }

                       

                      Thank u verymuch once again Hawkinson...

                       

                      With warm Regards,

                      K.Vel.