3 Replies Latest reply on May 5, 2014 9:53 PM by csm_phil

    Getting the correct page number

    schiuma24 Level 1

      Hi, Im stuck with this project...

       

      I have this xml tag

      <page id="p4" type="cyan">some content</page>

       

      so, what I want to do is, use this attributes to apply a B-Cyan, B-Magenta or B-Yellow master spread to

      (well to whatever page number there is on the tag) in this case page 4 (and 5 implicitly)

       

       

      im stuck here

       

       

      if( !myRoot.xmlAttributes.itemByName("xmlns:xml").isValid )

      myRoot.xmlAttributes.add( "xmlns:xml", "http://www.w3.org/XML/1998/namespace" );

      if( !myRoot.xmlAttributes.itemByName("xmlns:aid").isValid )

      myRoot.xmlAttributes.add( "xmlns:aid", "http://ns.adobe.com/Adobe InDesign/4.0/" );

      if( !myRoot.xmlAttributes.itemByName("xmlns:aid5").isValid )

      myRoot.xmlAttributes.add( "xmlns:aid", "http://ns.adobe.com/Adobe InDesign/5.0/" );

      //

      //**Types of pages

      var myPageNode= myRoot.evaluateXPathExpression("//page");

       

       

      for (var x = 0; x < myPageNode.length; x++){

       

                          var pageNumber  =  myPageNode[x].xmlAttributes.itemByName("id").value.replace("p","").replace(" ","");

                          var myTypeOfPage = myPageNode[x].xmlAttributes.itemByName("type").value;

       

                          if (myTypeOfPage = "cyan"){

                               app.activeDocument.pages.itemByName().appliedMaster = app.activeDocument.masterSpreads.item("B-Cyan")

                                                      }

                          if (myTypeOfPage = "magenta"){

                              app.activeDocument.pages.itemByName().appliedMaster = app.activeDocument.masterSpreads.item("B-Magenta")

                              }

                          if (myTypeOfPage = "yellow"){

                              app.activeDocument.pages.itemByName().appliedMaster = app.activeDocument.masterSpreads.item("B-Yellow")

                              }

                          };

       

       

      i dont know how to pass the correct value to: pages.itemByName( my page tag id number should get here )

       

       

      help!!!!!!!!!!!

        • 1. Re: Getting the correct page number
          csm_phil Level 4

          Hi schiuma24,

           

          I just modified your JS code, Please try the below code its works fine!

           

          var myDoc = app.activeDocument;
          var myRoot = myDoc.xmlElements[0];
          var myPageNode= myRoot.evaluateXPathExpression("//page");
          for (var x = 0; x < myPageNode.length; x++){
              var pageNumber  =  myPageNode[x].xmlAttributes.itemByName("id").value.replace(/[a-z]/gi, "");
              var myTypeOfPage = myPageNode[x].xmlAttributes.itemByName("type").value;
              if (myTypeOfPage == "cyan"){
                  myDoc.pages.item(pageNumber).appliedMaster = myDoc.masterSpreads.item("B-Cyan");
                  }
              else if (myTypeOfPage == "magenta"){
                  myDoc.pages.item(pageNumber).appliedMaster = myDoc.masterSpreads.item("B-Magenta");
                  }
              else if (myTypeOfPage == "yellow"){
                  myDoc.pages.item(pageNumber).appliedMaster = myDoc.masterSpreads.item("B-Yellow");
                  }
              };
          

           

          here is your mistake!!

             if (myTypeOfPage = "cyan"){// Here your not compare the the cyan, you assign the value.

           

          thx,

          csm_phil.

          • 2. Re: Getting the correct page number
            schiuma24 Level 1

            Hi Phil, im not comparing to cyan, im checking if the attribute of Type is cyan

            • 3. Re: Getting the correct page number
              csm_phil Level 4

              Hi schium24,

               

              You said your comparing the cyan value, but you you using the "=" is assign the value. not compare, If you need to compare you have to use "==" or etc.

               

              I tried my code its working fine. You get any error the above code.

               

              thx,

              csm_phil