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

move textFrame to specific layer

Engaged ,
Jan 20, 2017 Jan 20, 2017

Copy link to clipboard

Copied

So I am wanting to search through the entire document for all text frames that contain an underscore. If the text frame does include an underscore I am wanting to move that text frame to a specific layer called "Hypertext". Then I want to remove the underscore from that text frame. So in my code below I have it doing everything I have mentioned except I don't know how to get it to move to a specific layer. Any help would be appreciated!

#target illustrator

var doc = app.activeDocument;

var allText = doc.textFrames;

var searchString = /_/g;

var replaceString = " ";

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

    var thisTextFrame = allText;

    var newString = thisTextFrame.contents.replace(searchString, replaceString);

    if (newString != thisTextFrame.contents) {

        //alert("Contains an underscore");

        allText.move("Hypertext");

        thisTextFrame.contents = newString;

    }

}

TOPICS
Scripting

Views

444

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 , Jan 20, 2017 Jan 20, 2017

You can just use allText.move(targetLayer, ElementPlacement.PLACEATEND)

But you may want to go through the loop backwards in case the moving changes the length property of the collection of text frames.

Votes

Translate

Translate
Adobe
Valorous Hero ,
Jan 20, 2017 Jan 20, 2017

Copy link to clipboard

Copied

You can just use allText.move(targetLayer, ElementPlacement.PLACEATEND)

But you may want to go through the loop backwards in case the moving changes the length property of the collection of text frames.

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 ,
Jan 23, 2017 Jan 23, 2017

Copy link to clipboard

Copied

LATEST

Works perfect! Thank you! Here is the final code with the targetLayer variable....

#target illustrator

var doc = app.activeDocument;

var allText = doc.textFrames;

var searchString = /_/g;

var replaceString = " ";

var targetLayer = doc.layers.getByName("Hypertext");

for (var i = allText.length - 1; i >= 0; i--) {

    var thisTextFrame = allText;

    var newString = thisTextFrame.contents.replace(searchString, replaceString);

    if (newString != thisTextFrame.contents) {

        //alert("Contains an underscore");

        allText.move(targetLayer, ElementPlacement.PLACEATEND);

        thisTextFrame.contents = newString;

    }

}

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