0 Replies Latest reply on Mar 16, 2010 4:39 AM by gopaljay78

    Place XML into Library element

    gopaljay78 Level 1

      Hi,

       

       

      I am automating the process of placing library element as anchored element.

       

       

      The actual task is, I have an sidenote text in the indesign document. These text also contains   XML tags.

      I want to place this sidenote text into an library item called "MN1". This library item is a group of Picture and Textframes. Then this library item is placed into the document as anchored element.

       

       

       

      With my script, I am able place the XML into library item. But the problem is, I am not able to place this library item as anchored.

       

       

      My script is:

      ------------------------------------------------------------------------------------------ ----------------------------------------------------

       

      #target indesign-6.0
      var myDocument = app.activeDocument;
      sideart();
      // ***************************************************************
      // IMPORT BOXES INTO PAGES ON PASTEBOARD AREA
      // ***************************************************************
      function sideart()
      {
          var myCurrentLib = app.libraries.item(0);
          app.findGrepPreferences.findWhat = "(\\{\\{SS (.*?) (.*?)\\}\\})((.*\r)*?.*SE (.*?)\\}\\}\r?)";
          var found = myDocument.findGrep();
          for  (var i =0; i<found.length; i++)
          {
              found[i].select(SelectionOptions.replaceWith);
              var myLibName1 = found[i].contents.split(" ");
              var mySidID = myLibName1[1];

       

              var myLibName2 = myLibName1[2].split("=");
              var myLibName = myLibName2[1];

       

              var myRuleName1 = myLibName1[3].split("=");
              var myRuleName2 = myRuleName1[1].split("}}");
              var myRuleName = myRuleName2[0];

       

              app.cut();
              app.selection = null;       
              myAsset = myCurrentLib.assets.item(myLibName.toString());
              var libItem = myAsset.placeAsset(app.documents[0]);
              app.select(libItem[0].textFrames[0].parentStory.insertionPoints.item(0));       
              app.paste();
              libItem[0].textFrames[0].fit(FitOptions.frameToContent);
             
              app.findGrepPreferences.findWhat = "\\{\\{SE (.+?)\\}\\}\r";
              app.changeGrepPreferences.changeTo = "";
              libItem[0].textFrames[0].texts[0].changeGrep();
             
              app.findGrepPreferences.findWhat = "\\{\\{SS (.+?) (.+?)\\}\\}";
              app.changeGrepPreferences.changeTo = "";
              libItem[0].textFrames[0].texts[0].changeGrep();

       

              app.findGrepPreferences.findWhat = "";
              app.changeGrepPreferences.changeTo = "";
             
              app.findGrepPreferences.findWhat = "(\\{\\{SR " + mySidID + "\\}\\})";
              var foundref = myDocument.findGrep();
              if  (foundref.length > 0)
              {
                  /// HERE I WANT TO PLACE libItem AS ANCHORED ITEM WITH THE OBJECT STYLE APPLIED TO IT.
                  }
              else {
                  alert ("There is no Side art reference tag with ID: "+ mySidID);
                  }
             
              }
          }

      ------------------------------------------------------------------------------------------ ------------------------------

      My Indesign file look likes:

       

      Factors Affecting the Direction of Transport{{SR ch04mn1}}
      {{SS ch04mn1 L=MN1 O=TEST11}}The section on single-subject design was written by Dr. Stephen W. Stile.{{SE ch04mn1}}
      In Chapter 3, we saw that the reactant and product molecules in a metabolic reaction have different energies. We also saw that the energy change of a reaction—the difference between the reactant and product energies—determines the direction of the reaction and whether it proceeds spontaneously or requires energy. In the following section we see that similar principles govern the transport of molecules across membranes.

       

       

      ------------------------------------------------------------------------------------------ ------------------------------

       

       

       

      Please suggest how to place grouped library item with XML as anchored item.

       

      Thanks,

      Gopal