Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Doing absolute move using center reference point

Explorer ,
Nov 25, 2011 Nov 25, 2011

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

TOPICS
Scripting
2.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Nov 25, 2011 Nov 25, 2011

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

Translate
Mentor ,
Nov 25, 2011 Nov 25, 2011

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 25, 2011 Nov 25, 2011

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

Untitled.jpg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 25, 2011 Nov 25, 2011

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 25, 2011 Nov 25, 2011

Hi csm_phil,

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 25, 2011 Nov 25, 2011

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 26, 2011 Nov 26, 2011

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 26, 2011 Nov 26, 2011

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 26, 2011 Nov 26, 2011

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 26, 2011 Nov 26, 2011

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 26, 2011 Nov 26, 2011
LATEST

Hi John,

Okay thanks for information to share with me.

thx

csm_phil

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 25, 2011 Nov 25, 2011

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 25, 2011 Nov 25, 2011

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines