7 Replies Latest reply on May 30, 2011 5:43 PM by vze26m98

    Updating XML associated with a TextFrame?

    vze26m98 Level 1

      Hi all-

       

      With ExtendScript, using a ScriptUI dialog, I'm able to read and write XML data using these two references on close. boxContents is the text property of an EditTextBox:

       

       

      function DATA(ROW, COL){

        return app.documents[0].selection[ROW].associatedXMLElement.xmlElements[COL].xmlElements[0].cont ents;

      }

       

      function setDATA(ROW, COL, boxContents){

          app.documents[0].selection[ROW].associatedXMLElement.xmlElements[COL].xmlElements[0].cont ents = boxContents;

      }

       

      However, NOT on close, I'm able to read only, NOT write XML data using these two references:

       

      function tfDATA(i, COL){

        return app.documents[0].pages[0].textFrames[i].associatedXMLElement.xmlElements[COL].xmlElements [0].contents;

      }

       

      function tfSetDATA(i, COL, boxContents){

        $.writeln(i + ' : ' + COL + ' : ' + boxContents);

        app.documents[0].pages[0].textFrames[i].associatedXMLElement.xmlElements[COL].xmlElements [0].contents = boxContents;

      }

       

      Is there something obvious I'm missing here about TextFrames vs. selections, or writing data while a ScriptUI dialog is showing? Or does this sound like some mystery peculiar to my code?

      Thanks! Charles

        • 1. Re: Updating XML associated with a TextFrame?
          John Hawkinson Level 5

          Hi, Charles.

           

          This is the second time you've posted code without actually posting how you used it.  I didn't call you out on it the first time, but its' actually quite important! You have to show us how you are using the function, in order to demonstrate the problem. Even better if if you can give us a minimum case that we can easily use to reproduce your problem, then it's much easier to figure out  what's wrong with it.

          Are you calling tfSetDATA() with boxContents as a string? Or something else?

          What are the existing contents?

           

          That said, it's not obvious to me why it doesn't work. Which is why a test case would be helpful :-).

          1 person found this helpful
          • 2. Re: Updating XML associated with a TextFrame?
            vze26m98 Level 1

            Hi John-

             

            Thanks for your interest. I'll be sure to post working test cases in the future, but creating one at the moment seems like a lot of work. (Although therein would certainly lie the solution. ;-)

             

            Best wishes, Charles

            • 3. Re: Updating XML associated with a TextFrame?
              vze26m98 Level 1

              Actually, coming up with a test case that I think is related wasn't so hard. To make this work, you'll need document with two TextFrames. There's a button "Dirty" that will select the TextFrame of index 0 on close. If you place the select() function in the "Dirty" button's onClick handler, I get no result.

               

              Please let me know if this is still not enough to reproduce my issue.

               

              What I'm eager for is a solution that will enable me to place the select() function in the onClick handler and have it work.

               

              Thanks, Charles

               

              var dirty = false;

              var w = new Window('dialog', 'Select in onClick Test',[100,100,670,670]);

               

              w.btnNext = w.add('button', [125,445,215,85], 'Dirty');

              w.btnNext.onClick = function() {

                dirty = true;

                // This select() function doesn't work if uncommented.

                // app.documents[0].pages[0].textFrames[0].select();

              };

               

              w.cancelBtn = w.add('button', [298,445,388,85], 'Cancel');

              w.cancelBtn.onClick = function() {

                w.close(0);

              };

               

              w.applyBtn = w.add('button', [403,445,493,85], 'Ok', {name: 'ok'});

              w.applyBtn.onClick = function() {

                w.close(1);

              };

               

              w.show();

               

              if(dirty === true){

                // This select() function works if uncommented.

                app.documents[0].pages[0].textFrames[0].select();

              }

              • 4. Re: Updating XML associated with a TextFrame?
                John Hawkinson Level 5

                Sorry, I don't see what this example has to do with your original XML problem? Is there something in the middle missing?

                • 5. Re: Updating XML associated with a TextFrame?
                  vze26m98 Level 1

                  Those original XML functions were called from inside an onClick handler, and it seems that there's a lot I can't get to work within an onClick handler. So this maybe my problem.

                   

                  Thanks, Charles

                  • 6. Re: Updating XML associated with a TextFrame?
                    John Hawkinson Level 5

                    Well, why don't you show us calling your tfSetData(), so it's really hard to know the problem is. Please give an example that actually shows the problem!

                     

                    Are you specifying a non-default engine, like #targetengine session? That's often necessary with handlers.

                    • 7. Re: Updating XML associated with a TextFrame?
                      vze26m98 Level 1

                      Well, I converted my script from a dialog to a palette, and my original problems with tfSetDATA() and friends went away. So the "unrelated" example code I posted was a key to my solution.