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

relative position of an object to the margins

Engaged ,
Feb 25, 2020 Feb 25, 2020

Hi!
 
it's actually an easy task, obviously not for me...

I have a spread with facing pages. There are top-pargins, bottom-margins, left and right-margins. But the left and right ones should be inner- and outer-margins. Whenever I want to adjust the size and position of an object to the margins, the wide becomes 0. The reason is, that:
 
myPage.marginPreferences.top;
 
is not (e.g.) 200 mm but 10 mm (from the right side of the page). So you have 10 for the geometricBounds[1] (its the relative coordinate for x1) and 10 for geometricBounds[3] (the relative coordinate for x2). But I need the absolute values from the left edge (0mm) for both the left side page and the right side page. Is that doable?

 

Bildschirmfoto 2020-02-25 um 09.39.29.png

TOPICS
Print , Scripting
836
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

Engaged , Feb 26, 2020 Feb 26, 2020

Thanx Bob, thankx Brian.

My problem was the absolute Position on both sides of a double sided document.

But I found the solution, it's the red line:

 

var myDoc = app.activeDocument;

var theSelection = myDoc.selection;
var numSelection = theSelection.length;

app.doScript(auswahlCheck, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Process Table");

function auswahlCheck(){

objArray = [];

for (i=0; i<numSelection; i++){objArray.push(theSelection[i]);}

objArray.sort(function (a, b) {return Nu

...
Translate
Engaged ,
Feb 25, 2020 Feb 25, 2020

My recollection is that page.marginPreferences.top is the upper margin.

If you're changing the width of a object on the page, use marginPreferences.right for x1. Add the desired width for the object to x1. That's x2.To change the depth, start with marginPreferences.top.This puts your object at the upper left corner of the page. 

I'm not at a place where I can run InDesign right now, but if you still have trouble, I can look up some real javascript code later.

Bob

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
Community Expert ,
Feb 25, 2020 Feb 25, 2020

Not entirely sure what you are after, but you can access the bounds of a particular page (left or right) and subtract/add the margin from the appropriate bound maybe? Margin preferences will always just show the number that's set for the margins. But you want to get where the right margin is in the context of the whole spread? So to identify the absolute position of the right margin on a right spread, it would be pageRight.bounds[3] - pageRight.marginPreferences.right. Does that help? 

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 ,
Feb 26, 2020 Feb 26, 2020
LATEST

Thanx Bob, thankx Brian.

My problem was the absolute Position on both sides of a double sided document.

But I found the solution, it's the red line:

 

var myDoc = app.activeDocument;

var theSelection = myDoc.selection;
var numSelection = theSelection.length;

app.doScript(auswahlCheck, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Process Table");

function auswahlCheck(){

objArray = [];

for (i=0; i<numSelection; i++){objArray.push(theSelection[i]);}

objArray.sort(function (a, b) {return Number(a.geometricBounds[0]) - Number(b.geometricBounds[0]);});

for (i=0; i<numSelection; i++) {

var myObj = objArray[i];
var myPage = theSelection[i].parentPage;

var hoehe = myObj.geometricBounds[2]-myObj.geometricBounds[0];
var breite = myObj.geometricBounds[3]-myObj.geometricBounds[1];


if (i==0) {var y1 = myPage.bounds[0]+myPage.marginPreferences.top;}

else if (i>0) {
var vorherigesObj = objArray[i-1];
var y1 = vorherigesObj.geometricBounds[2]+1.764 ;
}

var x1 = myPage.bounds[1]+myPage.marginPreferences.left;
var y2 = y1+ hoehe;

if (i==2) {var y2 = myPage.bounds[2]-myPage.marginPreferences.bottom}

var x2 = myPage.bounds[3]-myPage.marginPreferences.right;

myObj.geometricBounds= [y1,x1,y2,x2];

}

}

 

 

 

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