2 Replies Latest reply on Oct 27, 2010 11:32 PM by PankChat

# CS5:JS: Facingpages & geometric bounds

Hi all,

Just posted the same question yesterday but thought it would not be clear enough for everyone.

My question is pretty straightforward,

I have an element(XMLElement) in my facingpages document, If the element located in left page, my below calculation to get the bounds of it(for creating new element in the same position), it always right, but if the element located in right page of facingpages, the bounds would be wrong. I other words, I want to get the bound of an element in facing pages doc(it should works for left/right pages), and it will be used to create an element in the same spot of old element in doc.

I use this:

..

//'elem' - the XMLElement referencing the page item to be replaced

var myObj = elem.xmlContent;

var bounds = myObj.geometricBounds;

var insertAt = Array( bounds[1], bounds[0]);

..

..

var newobjs = thepage.place( snpt,insertAt,thelayer,false,false ); // the new element wouldn't locate on the same position of original element ,if original element is on the right page

..

myObj.remove(); //clean up old object

Not sure how to calculate the X position of new element (newobjs ) with having the old X offset (bounds[1]) of original element for facing pages situation

Any help greatly appreciated,

Thanks,

Kamran

• ###### 1. Re: CS5:JS: Facingpages & geometric bounds

One more question: how can I find out my element located in Left/Right page of facing page?

thanks again.

• ###### 2. Re: CS5:JS: Facingpages & geometric bounds

Okay, I will try to give you a kick start to find out the page no. on which the element is placed. You can later do tweaking as per requirement. Suder/Harbs helped me out way back  for such requirement:

#include "glue code.jsx"

main();

function main(){

if (app.documents.length != 0){

var myDoc = app.activeDocument;

var myRuleSet = new Array (

new findElemPage("//myTag")

);

with(myDoc){

var elements = xmlElements;

__processRuleSet(elements.item(0), myRuleSet);

}

}

else{

exit();

}

function findElemPage(XPATH){

this.name = "findElemPage";

this.xpath = XPATH;

this.apply = function(myElement, myRuleProcessor)

{

var aFrame=myElement.paragraphs[0].parentTextFrames[0];

aFrame.select();

var myPg=getPage(app.selection[0]);

return true;

}

}

function getPage(theObj)

{

if (theObj.constructor.name == "Page") return theObj;

if (theObj.constructor.name == "Character" || theObj.constructor.name == "Paragraph")

return getPage(theObj.parentTextFrames[0]);

if (theObj.constructor.name == "Application")

{

// Frame is on an unexpected place...

alert ("Can't able to find the page");

exit(0);

}

return getPage(theObj.parent);

}

}

HTH,

Pankaj Chaturvedi

PS: If you are using CS5 note Harbs suggestion.