4 Replies Latest reply on Nov 8, 2017 9:23 AM by subieguy2

    Delete textFrame associated with variable

    subieguy2 Level 1

      I am wanting to scan through all open documents and look for a dynamic textFrame variable called   coverPageVolume

       

      When the script finds the textFrame associated with this variable.... I would like it to remove the textFrame.

       

      I can get it to change the contents...but any time I try to get it to remove the textFrame it locks my illustrator up.

       

      What am I doing wrong here?

       

      for (var i = 0; i < documents.length; i++) {
          var currentActiveDoc = app.documents[i];
          app.activeDocument = currentActiveDoc;
      
      
          var theDocVariables = currentActiveDoc.variables
      
      
          for (z = 0; z < theDocVariables.length; z++) {
      
      
              if (theDocVariables[z].name == "coverPageVolume") {
      
      
                  theDocVariables[z].pageItems[0].remove();
      
      
              }
          }
      }
      
        • 1. Re: Delete textFrame associated with variable
          Silly-V Adobe Community Professional

          Use another for loop:

           

          for(var j=theDocVariables[z].pageItems.length - 1; j > -1; j--){

               theDocVariables[z].pageItems[j].remove();

          };

          1 person found this helpful
          • 2. Re: Delete textFrame associated with variable
            subieguy2 Level 1

            Thank you for the input Silly-V !  When I try to run that script it still locks up my illustrator. I believe the issue is I have to delete the variable before I can delete the textFrame? Because when I run the following script it works....it is just slow.

             

            for (var i = 0; i < documents.length; i++) {
                var currentActiveDoc = app.documents[i];
                app.activeDocument = currentActiveDoc;
            
            
                var theDocVariables = currentActiveDoc.variables
            
            
                for (z = 0; z < theDocVariables.length; z++) {
            
            
                    if (theDocVariables[z].name == "coverPageVolume") {
                        // Make the textFrame blank
                        theDocVariables[z].pageItems[0].contents = "";
                        // Delete the associated variable
                        theDocVariables[z].remove();
            
            
                    }
                }
            
            
                var allText = currentActiveDoc.textFrames;
                var straypoints = [];
            
            
                // Check text frame length - Path Cleanup   
                for (j = 0; j < allText.length; j++) {
                    var itext = allText[j];
                    if (itext.textRange.length == 0)
                        straypoints.push(itext);
                }
                // Remove stray items - Path Cleanup 
                for (k = 0; k < straypoints.length; k++) {
                    straypoints[k].remove();
                    //alert(straypoints.length + " stray points removed");
                }
            }
            

             

            Any other methods you can think of that would allow me to delete the variable and textFrame?

            • 3. Re: Delete textFrame associated with variable
              Silly-V Adobe Community Professional

              Aha, indeed this is what happens to me too. It looks like remove() on all of the items will lock it up like you say.

              But, we can do this workaround to select all the items and then run a delete command:

               

              #target illustrator

              function test(){

                var doc = app.activeDocument;

                doc.selection = null;

                for(var i=0; i<doc.variables.length; i++){

                  if(doc.variables[i].name == "Variable3"){

                    for(var j=0; j<doc.variables[i].pageItems.length; j++){

                      doc.variables[i].pageItems[j].selected = true;

                    };

                  }

                };

                app.executeMenuCommand("clear");

              };

              test();

              1 person found this helpful
              • 4. Re: Delete textFrame associated with variable
                subieguy2 Level 1

                this is EXACTLY what I was trying to accomplish! Thank you Silly-V