4 Replies Latest reply on Feb 22, 2017 5:58 AM by Willam van Weelden

    ExtendScript - postworddocupdate

    easypay_mdb Level 1

      1) How can I instantly alter the topics, after generating/updating a Word-document?

         I tried this with no luck, see the results in my experiment.

       

      2) How can I make sure that my ExtendScript is running only on the Word-Documents that 'Generate or Update'?

         We will make projects with 20 or more linked Word-documents. So if one changes we won't run the script on all.

       

       

      Experiment:

       

      I have a script as following.

      Searching all topics within a project => cleanup all inline styling/topic.

      That works fine.

      I registered the script as an event.   (Event: postworddocupdate)

         I assumed that this event would trigger from the moment a generate or an update, of a Word-document, has finished. Meaning the topics are made.

       

      Why using this option:

      We put multiple Word-documents in one project. We do this with a link, without making a copy of the Word-document.

       

      I linked 2 Word-documents;

          - Doc_A.docx

          - Doc_B.docx

       

      I 'Generate' the Word-document Doc_A.docx

      Result in the 'Output View'

      Number of Word-documents present: 2                             => project.WordFileManager.count

      name Word-document: Doc_A    

      name Word-document: Doc_B

       

      Start removing inline styling !                                              => Start searching all topics within the project

       

      Topic: Hello

      Location: P:\Mdenbaes\RH_17\STK_N\Hello.htm                => default topic

       

      End removing inline styling !                                                => all topics within the project are handeld

       

       

      Next:

      I 'Generate' the Word-document Doc_B.docx

      Result in the 'Output View'

      Number of Word-documents present: 2                        

      name Word-document: Doc_A

      name Word-document: Doc_B

       

      Start removing inline styling !

       

      Topic: Sect steekkaart PC_124

      Location: P:\Mdenbaes\RH_17\STK_N\File_A\Doc_A\Doc_A.htm           => now the topic of the First Word-document is found.

       

      Topic: Hello

      Location: P:\Mdenbaes\RH_17\STK_N\Hello.htm

       

      End removing inline styling !

       

       

       

      As you can guess: If I 'Update' or 'Force update' one of the existing Word-documents: the topics of both Word-documents are shown in the 'Output View'.

        • 1. Re: ExtendScript - postworddocupdate
          prhmusic2 Level 2

          I don't have a solution for you - sorry - but I do a lot of linking to Word documents and the script you mention is interesting to me. Any chance you can post it in this thread?

          • 2. Re: ExtendScript - postworddocupdate
            Peter Grainge Adobe Community Professional (Moderator)

            It will not be possible to attach a script to a forum post. I suggest you use a Private Message to give your email address.

             


            See www.grainge.org for RoboHelp and Authoring information

             

             

            @petergrainge

            • 3. Re: ExtendScript - postworddocupdate
              prhmusic2 Level 2

              Thanks Peter - I sent a private message.

              • 4. Re: ExtendScript - postworddocupdate
                Willam van Weelden Adobe Community Professional & MVP

                Hi Marino,

                 

                The event delivers the full path of the word document that was updated as a parameter. From there, you can parse the linked word document XML to find the topics that are linked to the document. As you have probably found, ExtendScript offers various low level features, so more advanced stuf like this requires more work.

                 

                In my ExtendScript library I use the following code to get the linked files:

                 

                var Xpath = "//genfile/filename";

                  var loadFilesThatAreLinked = function(filepath) {

                  var LinkedFiles = new Array();

                        var ContainerFile = new File(filepath);

                        if(ContainerFile.exists)

                        {

                  var ContainerXML = new XML(readFile(ContainerFile));

                  var LinkedFilesinContainer = ContainerXML.xpath(Xpath).children();

                  for(var i = 0; i< LinkedFilesinContainer.length();i++)

                  {

                  LinkedFiles.push(LinkedFilesinContainer[i].toString());

                  }

                  return LinkedFiles;

                        } else {

                  return null;

                  }

                    }

                LinkedWordDocs = loadFilesThatAreLinked(projectpath()+WordContainer);

                 

                In here, I simply use an XPath to get all topics from a linked Word document, not from a specific Word document. This might be a good starting point. But you'll want to do it a little differently:

                • Load the projects RHWordDoc.apj. Either as an XML object as above or as a token. This might be easier because of the next step.
                • Iterate through the Word documents until you find the document that was updated.

                <word_doc>

                  <file_name>..\..\..\..\..\Desktop\Verduidelijking eis 6 Noordoostpolder.docx</file_name>

                 

                IF you want to get just the file name (if that's sufficient), use the filename() function from my library on the file path.

                • Once you found the correct word document, check the '/genfile/filename' element to find which topics belong to the word document.
                • Iterate through the topics and update them.