12 Replies Latest reply on Nov 26, 2011 2:57 AM by csm_phil

    Doing absolute move using center reference point

    jwvaughn

      I want to place a large number of images of varying aspect ratio using the center reference point at the same point in each page.  I have played with move and it appears to always use the top left point.  My interpretation of the documentation suggests that I would get the same results with transform.

       

      I realize that I could do the calculations to do the move but am hoping I am missing something and there is a much simpler way to do it.

       

      Thanks in advance

      Jerry

        • 1. Re: Doing absolute move using center reference point
          Muppet Mark Level 5

          Make your rectangle containers the size of the page, place and center the image then fit frame to content…

          • 2. Re: Doing absolute move using center reference point
            கற்பனை (Imagine) Level 3

            easy to use the align objects in scripts for aligning the object on page.  the snapshot is for your references.

             

            Untitled.jpg

            • 3. Re: Doing absolute move using center reference point
              csm_phil Level 4

              Hi Jerry,

               

              Please use the below JS code, its working only for the selected object.

               

               

              var myDoc = app.activeDocument;
              try{
                  var mySel = app.selection[0];
                  myDoc.align(mySel, AlignOptions.VERTICAL_CENTERS, AlignDistributeBounds.PAGE_BOUNDS);
                   myDoc.align(mySel, AlignOptions.HORIZONTAL_CENTERS, AlignDistributeBounds.PAGE_BOUNDS);
                  }
              catch(e){
                  alert("Please select the object!");
                  }
              
              
              

               

               

              thx

              csm_phil

              • 4. Re: Doing absolute move using center reference point
                கற்பனை (Imagine) Level 3

                Hi csm_phil,

                 

                you get it exactly what i mean,  Thanks for giving the code......

                • 5. Re: Doing absolute move using center reference point
                  John Hawkinson Level 5

                  I realize that I could do the calculations to do the move but am hoping I am missing something and there is a much simpler way to do it.

                  You should do the math. In particular, using the selection is a bad idea. Bad for performance, bad for idempotency, and bad philosophically.

                  1 person found this helpful
                  • 6. Re: Doing absolute move using center reference point
                    jwvaughn Level 1

                    Just to clarify...

                     

                    The center point on the object to a chosen point on the page other than exact center of the page.

                     

                    Thus far, John is confirming my suspicions.

                     

                    Jerry

                    • 7. Re: Doing absolute move using center reference point
                      jwvaughn Level 1

                      I finally just did the calculations - it does not seem as elegent as a move using the center reference but it works.

                       

                      here is a snippet of the code with the warning that 6.125 and 5.0 are hard coded and they really shouldn't be and OCD made me round things...

                       

                      xy = myObject.geometricBounds
                      height  = xy(2) - xy(0)
                      width = xy(3) - xy(1)
                      x_position = round(6.125 - (width / 2),3)
                      y_position = round(5.0 - (height / 2),3)
                      myObject.move Array(x_position, y_position )

                       

                      Jerry

                      • 8. Re: Doing absolute move using center reference point
                        csm_phil Level 4

                        Hi John Hawkinson,

                         

                        Actually, jerry is wants to objects to be center of the page thats all. So give the js code for the simplest way to do for center align for select object only.

                        I don't know why you wrote the "Bad for performance, bad for idempotency, and bad philosophically" If you say all the comments, then why adobe give this method, and also this methods is working fine,  if its not working so whats the problem for my js code, can you please explain, Your are the good programmer i know your stuff, just you clarify i want to change the your mehtods in future.

                        John Hawkinson wrote:

                         

                        I realize that I could do the calculations to do the move but am hoping I am missing something and there is a much simpler way to do it.

                        You should do the math. In particular, using the selection is a bad idea. Bad for performance, bad for idempotency, and bad philosophically.

                         

                        thx

                        csm_phil

                        • 9. Re: Doing absolute move using center reference point
                          John Hawkinson Level 5

                          csm_phil: Your English is quite confusing. Please remember to end sentences with periods. I assume you meant to say:

                           

                          I don't know why you wrote  "Bad for performance, bad for idempotency, and bad philosophically" when this method is working.  If its working, what is the problem? Can you please explain.

                          (I'm still not sure what you meant by "i want to change the your mehtods.")

                           

                          Because something is working does not mean it is right.

                          Because something is working does not mean it is good.

                          It may cause problems in the future. Or it may have side effects.

                           

                          I wrote four things:

                           

                          Using the selection is a bad idea. This is well-accepted by experienced scripters. Scripts should avoid using the selection wherever possible. But why? I tried to explain in brief:

                           

                          Bad for performance: Interacting with the selection is slower. InDesign has to deal with updating the display and the UI when the selection is involved, when it would not otherwise have to do so. Anytime you interact with the selection your script will be slower. That slowness may not matter most of the time, such as when you are donly doing something once.

                           

                          Bad for idempotency: When you change the selection, it becomes difficult to repeat your work, and you do not leave the state of the program as you found it. If something else is depending on the selection, then you will screw that up. It is like changing a global variable. The best solution is not to change it, but to use a local variable instead. As a workaround, you can save the old value of the selection, perform your work, and then restore the selection. But that is imperfect. What if your code is running in an event handler? What if two pieces of code that use the selection are running in parallel? What if there are thread concurrency issue? Probably not the case in CS5.5, but what about CS7?

                           

                          Bad philosophically: This one is harder to explain. I think it really boils down to, if your script is not affecting the user interface, it should not alter portions of the user interface. The selection should be considered out-of-bounds for most scripts. This is really a restatement of the previous claims, especially "bad idea," so maybe it does not count on its own. But I repeat it because it is worth repeating.

                           

                          If you're really careful, using the selection can work. But much of the time it causes problems, either in the present or in the future. It is good to avoid problems where feasible.

                           

                          I hope this post helps you to understand what I meant.

                          • 10. Re: Doing absolute move using center reference point
                            csm_phil Level 4

                            Hi John,

                             

                            Thanks for understanding my previous post replies.

                             

                            Any way i will change the method of using selection command, Otherwise i used most of the tool creation using selection property. Any way thanks for your help.

                             

                            One Doubt In this case what is the myObject i think definitely he want to select the one object or how it make sense.

                             

                            xy = myObject.geometricBounds

                            height  = xy(2) - xy(0)

                            width = xy(3) - xy(1)

                            x_position = round(6.125 - (width / 2),3)

                            y_position = round(5.0 - (height / 2),3)

                            myObject.move Array(x_position, y_position )

                             

                             

                            thx

                            csm_phil.

                            • 11. Re: Doing absolute move using center reference point
                              John Hawkinson Level 5

                              One Doubt In this case what is the myObject i think definitely he want to select the one object or how it make sense.

                              Why? He has an object myObject.

                              Why do you think he wants to select it?

                               

                              He has already told us that he wants to place multiple images with a comon center.

                              • 12. Re: Doing absolute move using center reference point
                                csm_phil Level 4

                                Hi John,

                                 

                                Okay thanks for information to share with me.

                                 

                                thx

                                csm_phil