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,



        • 1. Re: CS5:JS: Facingpages & geometric bounds
          Kamrun. Level 1

          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
            PankChat Level 1

            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:




            Suppose your element is myTag:


            #include "glue code.jsx"


            function main(){

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

            var myDoc = app.activeDocument;

            var myRuleSet = new Array (

            new findElemPage("//myTag")




            var elements = xmlElements;

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





            alert("You have no document open!");





            function findElemPage(XPATH){

            this.name = "findElemPage";

            this.xpath = XPATH;

            this.apply = function(myElement, myRuleProcessor)


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


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

            alert (myPg.name);

            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");



            return getPage(theObj.parent);





            Pankaj Chaturvedi


            PS: If you are using CS5 note Harbs suggestion.