• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Delete textFrame associated with variable

Engaged ,
Nov 07, 2017 Nov 07, 2017

Copy link to clipboard

Copied

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;

    app.activeDocument = currentActiveDoc;

    var theDocVariables = currentActiveDoc.variables

    for (z = 0; z < theDocVariables.length; z++) {

        if (theDocVariables.name == "coverPageVolume") {

            theDocVariables.pageItems[0].remove();

        }

    }

}

TOPICS
Scripting

Views

495

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Nov 08, 2017 Nov 08, 2017

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.name == "Variable3"){

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

        doc.variables.pageItems.selected = true;

      };

    }

  };

 

...

Votes

Translate

Translate
Adobe
Valorous Hero ,
Nov 07, 2017 Nov 07, 2017

Copy link to clipboard

Copied

Use another for loop:

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

     theDocVariables.pageItems.remove();

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 08, 2017 Nov 08, 2017

Copy link to clipboard

Copied

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;

    app.activeDocument = currentActiveDoc;

    var theDocVariables = currentActiveDoc.variables

    for (z = 0; z < theDocVariables.length; z++) {

        if (theDocVariables.name == "coverPageVolume") {

            // Make the textFrame blank

            theDocVariables.pageItems[0].contents = "";

            // Delete the associated variable

            theDocVariables.remove();

        }

    }

    var allText = currentActiveDoc.textFrames;

    var straypoints = [];

    // Check text frame length - Path Cleanup  

    for (j = 0; j < allText.length; j++) {

        var itext = allText;

        if (itext.textRange.length == 0)

            straypoints.push(itext);

    }

    // Remove stray items - Path Cleanup

    for (k = 0; k < straypoints.length; k++) {

        straypoints.remove();

        //alert(straypoints.length + " stray points removed");

    }

}

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Nov 08, 2017 Nov 08, 2017

Copy link to clipboard

Copied

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.name == "Variable3"){

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

        doc.variables.pageItems.selected = true;

      };

    }

  };

  app.executeMenuCommand("clear");

};

test();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 08, 2017 Nov 08, 2017

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines