11 Replies Latest reply on Jun 4, 2012 4:31 AM by karthiIndesign

    how to image frame move top of the page.

    karthiIndesign

      if suppose the the page contain only one image.that image move to the top of the page.other pages will skip.i have tried.the below code not working.

       

       

      =====================

       

      var myDocument=app.activeDocument;

      var myPages=myDocument.pages;

      for(p=0;p<myPages.length;p++)

      {

              var myGraphics=myPages[p].allGraphics;

              var myPageWidth=myDocument.documentPreferences.pageWidth;

              if(myGraphics.length==1)

              {

                  for(j=0;j<myGraphics.length;j++)

                  {

                      if(myPages[p].side == PageSideOptions.leftHand)

                      {

                          var myX2 = myPages[p].marginPreferences.left;

                          var myX1 = myPages[p].marginPreferences.right;

                      }

                      else

                      {

                          var myX1 = myPages[p].marginPreferences.left;

                          var myX2 = myPages[p].marginPreferences.right;

                      }

                      var myY1 = myPages[p].marginPreferences.top;

                      var myX2 = myPageWidth - myX2;    

                      var myImageheight=myGraphics[j].parent.geometricBounds[2]-myGraphics[j].parent.geometricBound s[0];

                      var myY2=myY1+myImageheight;

                     //imageframe move top of the page

                       myGraphics[j].geometricBounds=[myY1,myX1,myY2,myX2];

       

                 }

             }

      }

      ================

      Thank you.

       

      Message was edited by: karthiIndesign

        • 1. Re: how to image frame move top of the page.
          Green4ever Level 3

          Use this code and try....

           

          var myDocument=app.activeDocument;
          var myPages=myDocument.pages;
          for(p=0;p<myPages.length;p++)
          {
                  var myGraphics=myPages[p].allGraphics;
                  var myPageWidth=myDocument.documentPreferences.pageWidth;
                  if(myGraphics.length==1)
                  {
                      var myX2, myX1, myY1, myY2;
                      for(j=0;j<myGraphics.length;j++)
                      {
                          if(myPages[p].side == PageSideOptions.leftHand)
                          {
                              myX2 = myPages[p].marginPreferences.left;
                              myX1 = myPages[p].marginPreferences.right;
                          }
                          else
                          {
                              myX1 = myPages[p].marginPreferences.left;
                              myX2 = myPages[p].marginPreferences.right;
                          }
                          myY1 = myPages[p].marginPreferences.top;
                          myX2 = myPageWidth - myX2;    
                          var myImageheight=myGraphics[j].parent.geometricBounds[2]-myGraphics[j].parent.geometricBounds[0];
                          myY2=myY1+myImageheight;
                         //imageframe move top of the page
                           myGraphics[j].parent.move([myY1, myX1]);
                     }
                 }
          }
          
          1 person found this helpful
          • 2. Re: how to image frame move top of the page.
            karthiIndesign Level 1

                  Thank you for your interest.

                 input document:

            ipdoc.JPG

                 after running the script the frame not resized exactly.

                outputdocument:

            opdoc.JPG

            • 3. Re: how to image frame move top of the page.
              Green4ever Level 3

              show me the output you want? and then i'll try it?

              • 4. Re: how to image frame move top of the page.
                [Jongware] Most Valuable Participant

                Do you mean something like this? It will move any single graphic on a page up to the top margin and will not resize anything else. I have a hard time following all that extra code you wrote, and that Greenie also included -- it seems to me it's not necessary ... (That is, if I understand correctly what you want to achieve here!)

                 

                for (p=0; pp=app.activeDocument.pages[p],p<app.activeDocument.pages.length; p++)
                if (pp.allGraphics.length == 1)
                  pp.allGraphics[0].parent.move([pp.allGraphics[0].parent.geometricBounds[1], pp.marginPreferences.top]);
                
                1 person found this helpful
                • 5. Re: how to image frame move top of the page.
                  [Jongware] Most Valuable Participant

                  By the way,

                   

                  karthiIndesign wrote:

                  the below code not working.

                   

                  With a statement like that you should indicate why it is "not working". Are you not double-clicking the script to make it run? Do you get an error? Does it not do anything? Does it do something else?

                  • 6. Re: how to image frame move top of the page.
                    karthiIndesign Level 1

                    i mean the tool aim not working perfectly.

                    • 8. Re: how to image frame move top of the page.
                      karthiIndesign Level 1

                      thankyou for code generalization.

                      • 9. Re: how to image frame move top of the page.
                        [Jongware] Most Valuable Participant

                        Yeah, but that still doesn't tell us anything. Of course it is "not working perfectly" -- if it was, you shouldn't have posted it.

                         

                        So, for the next time, also explain what it didn't do what you expected it to.

                        • 10. Re: how to image frame move top of the page.
                          [Jongware] Most Valuable Participant

                          If it answered your question, please mark the post so other people know (a) to read it if they need something similar, and (b) not to read it if they think they know the answer as well.

                          • 11. Re: how to image frame move top of the page.
                            karthiIndesign Level 1

                            i got the solution.

                            var myDocument=app.activeDocument;
                            var myPages=myDocument.pages;
                            for(p=0;p<myPages.length;p++)
                            {
                                    var myGraphics=myPages[p].allGraphics;
                                    var myPageWidth=myDocument.documentPreferences.pageWidth;
                                    if(myGraphics.length==1)
                                    {
                                        var myX2, myX1, myY1, myY2;
                                        for(j=0;j<myGraphics.length;j++)
                                        {
                                            if(myPages[p].side == PageSideOptions.leftHand)
                                            {
                                                myX2 = myPages[p].marginPreferences.left;
                                                myX1 = myPages[p].marginPreferences.right;
                                            }
                                            else
                                            {
                                                myX1 = myPages[p].marginPreferences.left;
                                                myX2 = myPages[p].marginPreferences.right;
                                            }
                                            myY1 = myPages[p].marginPreferences.top;
                                            myX2 = myPageWidth - myX2;   
                                            var myImageheight=myGraphics[j].parent.geometricBounds[2]-               myGraphics[j].parent.geometricBounds[0];
                                            myY2=myY1+myImageheight;

                                                               var mygraphicmove= myGraphics[j].parent.duplicate([myY1,myX1]);              

                                                               myGraphics[j].parent.remove();

                                                               mygraphicmove.textWrapPreferences.textWrapMode = TextWrapModes.BOUNDING_BOX_TEXT_WRAP;


                                       }
                                   }
                            }

                            Thank you.