2 Replies Latest reply on Jul 8, 2016 4:22 AM by prtamil

    Script error

    prtamil Level 1

      I am trying to apply right indent for the paragraphs when they come with the XML tag P with attribute Type and its value icon. Here is my code.

       

      myFilePath="C:/Program Files/Adobe/Adobe InDesign CC 2015 (32-bit)/Scripts/XML Rules/glue code.jsx"
      app.scriptPreferences.userInteractionLevel=UserInteractionLevels.interactWithAll;
      var myFile = File(myFilePath);
      app.doScript(myFile);            
      
      
      
      if (app.documents.length != 0){
          var myDocument = app.documents.item(0);
          var myRuleSet = new Array (new anchor);
          with(myDocument){
              var elements = xmlElements;
              __processRuleSet(elements.item(0), myRuleSet);
              }
          }
      else{
          alert("No open document");
          }
      
      
      
      function anchor(){
          this.name = "image";
          this.xpath = "//p";
          this.apply = function(myElement, myRuleProcessor){
              with(myElement){
                  var myName=myElement.xmlAttributes.itemByName("type").value;
      //~             app.select(myElement);
                  alert(myName);
                  if (myName == "icon"){
                          app.select(texts);        
                      app.selection[0].rightIndent=21;
                      }
                  app.selection = null;
                  }
              return true;
              }
          }
      alert("Done");
      

       

       

       

      While I run this script I am getting below error

      Capture1.PNG

       

      XML structure is below

       

      Capture.PNG

        • 1. Re: Script error
          csm_phil Level 4

          Hi prtamil,

           

          Use the below JS code, I've modified.

           

          #include "/Program Files/Adobe/Adobe InDesign CC 2015/Scripts/XML Rules/glue code.jsx"
            
          if (app.documents.length != 0){  
              var myDocument = app.documents.item(0);  
              var myRuleSet = new Array (new anchor);  
              with(myDocument){  
                  var elements = xmlElements;  
                  __processRuleSet(elements.item(0), myRuleSet);  
                  }  
              }  
          else{  
              alert("No open document");  
              }  
            
          function anchor(){  
              this.name = "anchor";  
              this.xpath = "//p[@type='icon']";  
              this.apply = function(myElement, myRuleProcessor){  
                  with(myElement){  
                      var myName=myElement.xmlContent;
                      myName.rightIndent=21;  
                      }  
                  return true;  
                  }  
              }  
          alert("Done");  
          
          

           

           

          thx,

          csm_phil

          • 2. Re: Script error
            prtamil Level 1

            Thanks a lot csm_phil.

             

            It works fine, can you please help me to learn what  causes error in my coding?