3 Replies Latest reply on Apr 30, 2014 1:29 PM by Mi_D

    [JS][CS5] PlaceXML fails. What Am I Doing Wrong?

    tregenza

      Hi everyone,

       

      I have an XML file which I can place manually but I'm trying to automate the process with a script but I cannot work out why the script is failing. It falls over with an Error 30477.

       

      The document has several different types of master spreads and the XML is organised into appropriate sections. Based on the section in the XML file, I need to create a page, apply the right master page and place the XML.

       

      The script creates the page, applies the master but fails when placing the xmlElement. I've tried several different approaches and searched everywhere for an answer but cannot work out why.

       

      Can anyone tell me what I'm doing wrong?

          

       

      /*  Places XML section on appropriate pages */

       

      alert("Starting Process");

      var myDocument = app.activeDocument;

       

      var currentPage;

      var masterSpread;

       

      var xmlBook = myDocument.xmlElements[0].xmlElements[0];

       

      if ( xmlBook.markupTag.name.toString() == 'book' ) {

          // In the right place

          for ( var lp = 0; lp < xmlBook.xmlElements.length; lp++) {

              var xmlElement = xmlBook.xmlElements[lp]; // Structural element in the book

              switch ( xmlElement.markupTag.name.toString() ) {

                  case "standard":

                     

                      var currentPage = myDocument.pages.add(LocationOptions.AT_END);

                      var masterSpread = myDocument.masterSpreads.itemByName('S-Standard');

                      currentPage.appliedMaster = masterSpread;   

       

                      var targetFrame = myDocument.pages.lastItem().textFrames[0];

         

                      /* Throws:   Error 30477 Invalid value for parameter 'using' */               

                      xmlElement.placeXML(targetFrame);

                     

                      break;

              }

             

          }

       

      } else {

          alert(xmlBook.markupTag.name);   

          throw { name: 'FatalError', message: 'XML Structure wrong' };

       

      }

       

       

      Sample XML

       

      <?xml version="1.0" encoding="UTF-8"?>

      <document domain="http://6d6rpg.com/wiki/" id="member:tregenza:pdfprinttestbook" revision="0" lastmod="1398592877">

      <book colour="#f05177" bookTitle="PDF Print Test Book" >

      <standard><header4 >Test Wiki Page</header4>

      <p>Test of wiki content for the &lt;page&gt; syntax.</p>

      <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus facilisis suscipit laoreet. Nunc vel viverra est. Morbi massa arcu, suscipit eget massa a, faucibus pellentesque mi. Cras tristique, nibh cursus faucibus vestibulum, est velit gravida odio, vitae pretium erat libero non sem. Cras commodo gravida rhoncus. Nam nec rutrum leo. Fusce gravida rutrum ipsum, ut ultricies libero pulvinar in. Suspendisse at rhoncus mi. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla porta quam vel turpis iaculis, ut hendrerit nibh semper. Nunc ornare egestas dui eu dictum. Mauris lorem dolor, dignissim nec velit et, semper venenatis libero. Pellentesque gravida mauris magna, at pretium tellus tempor sed.</p>

      <p>Quisque venenatis vehicula ultricies. Nulla sit amet ornare orci, sed molestie mi. Proin quis tempus ante. Etiam auctor aliquam pretium. Nam pellentesque justo sem, a lacinia tortor euismod sed. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Suspendisse ut neque ipsum. Nam convallis at metus non ullamcorper. Morbi a orci quam. Quisque rhoncus neque a auctor porttitor. Fusce auctor cursus tellus, luctus aliquet turpis vehicula ut. Donec at sagittis erat. Vivamus sit amet elit vel dolor sollicitudin molestie sed sed turpis.</p>

      <p>Integer dictum, mauris non aliquet scelerisque, nunc odio mattis sapien, sit amet porttitor mi ante quis ligula. Fusce in feugiat arcu, at cursus magna. Aliquam dignissim lorem in risus adipiscing, vitae iaculis sem ullamcorper. Cras eu libero sem. Nulla cursus mattis luctus. Sed porttitor, arcu consectetur malesuada ultrices, sapien nunc tincidunt justo, vel rutrum diam quam eget mi. Praesent pretium ac risus sed tempor. Cras condimentum, mi id facilisis pretium, turpis ipsum mollis nisi, ac posuere nunc dui vitae risus. Sed adipiscing purus a diam accumsan, a rhoncus tortor pellentesque. Morbi et dui quis mauris ornare commodo et quis eros. </p>

      <header4 >Test Wiki Page</header4>

      <p>Test of wiki content for the &lt;page&gt; syntax.</p>

      <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus facilisis suscipit laoreet. Nunc vel viverra est. Morbi massa arcu, suscipit eget massa a, faucibus pellentesque mi. Cras tristique, nibh cursus faucibus vestibulum, est velit gravida odio, vitae pretium erat libero non sem. Cras commodo gravida rhoncus. Nam nec rutrum leo. Fusce gravida rutrum ipsum, ut ultricies libero pulvinar in. Suspendisse at rhoncus mi. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla porta quam vel turpis iaculis, ut hendrerit nibh semper. Nunc ornare egestas dui eu dictum. Mauris lorem dolor, dignissim nec velit et, semper venenatis libero. Pellentesque gravida mauris magna, at pretium tellus tempor sed.</p>

      <p>Quisque venenatis vehicula ultricies. Nulla sit amet ornare orci, sed molestie mi. Proin quis tempus ante. Etiam auctor aliquam pretium. Nam pellentesque justo sem, a lacinia tortor euismod sed. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Suspendisse ut neque ipsum. Nam convallis at metus non ullamcorper. Morbi a orci quam. Quisque rhoncus neque a auctor porttitor. Fusce auctor cursus tellus, luctus aliquet turpis vehicula ut. Donec at sagittis erat. Vivamus sit amet elit vel dolor sollicitudin molestie sed sed turpis.</p>

      <p>Integer dictum, mauris non aliquet scelerisque, nunc odio mattis sapien, sit amet porttitor mi ante quis ligula. Fusce in feugiat arcu, at cursus magna. Aliquam dignissim lorem in risus adipiscing, vitae iaculis sem ullamcorper. Cras eu libero sem. Nulla cursus mattis luctus. Sed porttitor, arcu consectetur malesuada ultrices, sapien nunc tincidunt justo, vel rutrum diam quam eget mi. Praesent pretium ac risus sed tempor. Cras condimentum, mi id facilisis pretium, turpis ipsum mollis nisi, ac posuere nunc dui vitae risus. Sed adipiscing purus a diam accumsan, a rhoncus tortor pellentesque. Morbi et dui quis mauris ornare commodo et quis eros. </p>

      </standard>

      <appendix>

      <header4 >Autofire</header4>

      <p>Quisque venenatis vehicula ultricies. Nulla sit amet ornare orci, sed molestie mi. Proin quis tempus ante. Etiam auctor aliquam pretium. Nam pellentesque justo sem, a lacinia tortor euismod sed. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Suspendisse ut neque ipsum. Nam convallis at metus non ullamcorper. Morbi a orci quam. Quisque rhoncus neque a auctor porttitor. Fusce auctor cursus tellus, luctus aliquet turpis vehicula ut. Donec at sagittis erat. Vivamus sit amet elit vel dolor sollicitudin molestie sed sed turpis.</p>

      </appendix>

      </book></document>

        • 1. Re: [JS][CS5] PlaceXML fails. What Am I Doing Wrong?
          Mi_D Level 3

          xmlElement.placeXML(targetFrame);this line is wroung

          select text frame  . placeXML(select node here) for eg

           

          targetFrame.placeXML(xmlElement);

           

          Mi_D

          1 person found this helpful
          • 2. Re: [JS][CS5] PlaceXML fails. What Am I Doing Wrong?
            tregenza Level 1

            Thanks Mi_D but it has not fixed the problem.

             

            I now get Error 45 Object Is Invalid.

             

             

            /*  Places XML section on appropriate pages */

             

             

            alert("Starting Process");

            var myDocument = app.activeDocument;

            var currentPage;

            var masterSpread;

             

            var xmlBook = myDocument.xmlElements[0].xmlElements[0];

             

            if ( xmlBook.markupTag.name.toString() == 'book' ) {

             

                // In the right place

                for ( var lp = 0; lp < xmlBook.xmlElements.length; lp++) {

                    var xmlElement = xmlBook.xmlElements[lp]; // Structural element in the book

                    switch ( xmlElement.markupTag.name.toString() ) {

                        case "standard":

             

                            var currentPage = myDocument.pages.add(LocationOptions.AT_END);

                            var masterSpread = myDocument.masterSpreads.itemByName('S-Standard');

                            currentPage.appliedMaster = masterSpread;  

             

                            var targetFrame = myDocument.pages.lastItem().textFrames[0];

             

                            /* Throws:   Error 30477 Invalid value for parameter 'using' */              

            //                 xmlElement.placeXML(targetFrame);    // Originial Code

             

                            // Throws:  Error 45 Object Is Invalid

                            targetFrame.placeXML(xmlElement);  // Code by Mi_D

                            break;

                    }

                }

             

            } else {

                alert(xmlBook.markupTag.name);  

                throw { name: 'FatalError', message: 'XML Structure wrong' };

            }

            • 3. Re: [JS][CS5] PlaceXML fails. What Am I Doing Wrong?
              Mi_D Level 3

              can u send ur indd file