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

Can someone share script that takes text and adds it to an object.

Explorer ,
Apr 14, 2022 Apr 14, 2022

Copy link to clipboard

Copied

I do have some figures (in randomly named layer) with random number of edges and colours and random texts (in another randomly named layer) placed on them (text can be on multyple rows). I want the figures to be named as the text on them.

The only certen thing is that the text will aways be placed 100% on the figure.

Starting point.JPG

 

Endgoal:

Select the text from one of the layers, then select a figure from the other layer and run the script, after that figure should get the text name (inside the layer).

 

If it can be automated more as selecting all texts and figures at once and runing the script this would be amazing (if not it can be done one by one).

End Goal.JPG

TOPICS
Scripting

Views

170

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

Guide , Apr 15, 2022 Apr 15, 2022

This is based on the text being completely within the bounding box of the path. See if it does what you want. (It does not test whether the text is in front or behind the path.)

 

// select all texts and paths in question
var frames = [];
var paths = [];
for (var i = 0; i < app.selection.length; i++) {
    if (app.selection[i].typename == "TextFrame") {
        frames.push(app.selection[i]);
    } else if (app.selection[i].typename == "PathItem") {
        paths.push(app.selection[i]);
    }
}
for
...

Votes

Translate

Translate
Adobe
Guide ,
Apr 15, 2022 Apr 15, 2022

Copy link to clipboard

Copied

quote

The only certen thing is that the text will aways be placed 100% on the figure.

By @D.S..


It's possible to test whether the text is within the bounding box of the path. Testing whether the text is literally completely within the path may be impractical.

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
Explorer ,
Apr 15, 2022 Apr 15, 2022

Copy link to clipboard

Copied

Mmmm my point was that that's the only think I know (not necessery to use it), that the text will be inside the boundrys. I need to select one text (does not mater if it is inside the boundrys or outside) that can be multyple rows

 

Example 1 (one textbox):

Name
1

 

Example 2 (one textbox):

Birds
Fly

 

and select one figure with name <Path> (default one after creating a figure with the pen tool), after running the script I want the figure name to become what is written inside the text box.

 

Example:

Select
Textbox: Name 1
Shape: <path>

 

Run the script

 

Textbox: Name 1
Shape: Name 1

 

Do you think this is possible?

 

If you need further explanation please tell me. 🙂 

 

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
Guide ,
Apr 15, 2022 Apr 15, 2022

Copy link to clipboard

Copied

This is based on the text being completely within the bounding box of the path. See if it does what you want. (It does not test whether the text is in front or behind the path.)

 

// select all texts and paths in question
var frames = [];
var paths = [];
for (var i = 0; i < app.selection.length; i++) {
    if (app.selection[i].typename == "TextFrame") {
        frames.push(app.selection[i]);
    } else if (app.selection[i].typename == "PathItem") {
        paths.push(app.selection[i]);
    }
}
for (var i = 0; i < paths.length; i++) {
    for (var j = 0; j < frames.length; j++) {
        var b1 = frames[j].geometricBounds;
        var b2 = paths[i].geometricBounds;
        if ((b1[0] > b2[0] && b1[2] < b2[2]) && 
            (b1[1] < b2[1] && b1[3] > b2[3])) {
            paths[i].name = frames[j].contents;
        }
    }
}

 

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
Explorer ,
Apr 15, 2022 Apr 15, 2022

Copy link to clipboard

Copied

LATEST

Pf you blew my mind. It works perfectly.

I am amazed by your skills honestly!

Thank you for your time. I really apreciate it!

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