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

Auto add text to a path

Community Beginner ,
Nov 01, 2023 Nov 01, 2023

Copy link to clipboard

Copied

Hi . we have lots of text box that we need to use Type On Path tool and add them on some curved lineds, 
Is it possible to use Scripting for this?

I mean when i select both a text box and a line(drawed by Pen tool)(Screenshot_1) , and then Run the Script, it automaticlly put the text from the text box  using  the type on path tools on the cureved line(Screenshot_2)

TOPICS
Scripting

Views

802
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 2 Correct answers

Participant , Nov 02, 2023 Nov 02, 2023

This does the job:

var doc = app.activeDocument;
var tf;
var path;

if(String(doc.selection[0]).indexOf("Polygon") > -1) {
	path = doc.selection[0];
	tf = doc.selection[1];
} else {
	tf = doc.selection[0];
	path = doc.selection[1];
}

var tp = path.textPaths.add();
tp.contents = tf.contents;

Prior to script execution, you need to select one curved line and one text frame.

 

Before:

before.PNG After:

after.PNG

 

Votes

Translate
Participant , Nov 02, 2023 Nov 02, 2023

The paragraph style method is the easier one. Just append this line to the script above:

tp.texts[0].appliedParagraphStyle = doc.paragraphStyles.item("myParStyle");

Make sure to replace myParStyle with the actual paragraph style name.

Votes

Translate
Participant ,
Nov 02, 2023 Nov 02, 2023

Copy link to clipboard

Copied

This does the job:

var doc = app.activeDocument;
var tf;
var path;

if(String(doc.selection[0]).indexOf("Polygon") > -1) {
	path = doc.selection[0];
	tf = doc.selection[1];
} else {
	tf = doc.selection[0];
	path = doc.selection[1];
}

var tp = path.textPaths.add();
tp.contents = tf.contents;

Prior to script execution, you need to select one curved line and one text frame.

 

Before:

before.PNG After:

after.PNG

 

____________________
Robotic Process Automation in Desktop Publishing (Book): https://doi.org/10.1007/978-3-658-39375-5

Votes

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
Community Beginner ,
Nov 02, 2023 Nov 02, 2023

Copy link to clipboard

Copied

I tested the code and it is functioning correctly. Nice work!

Votes

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
Community Beginner ,
Nov 02, 2023 Nov 02, 2023

Copy link to clipboard

Copied

just out of curiosity , is it possible the text on the path keep the style of the text box? or is it possible to give a certain paragraph style to the text on the path after being created?

Votes

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
Participant ,
Nov 02, 2023 Nov 02, 2023

Copy link to clipboard

Copied

The paragraph style method is the easier one. Just append this line to the script above:

tp.texts[0].appliedParagraphStyle = doc.paragraphStyles.item("myParStyle");

Make sure to replace myParStyle with the actual paragraph style name.

____________________
Robotic Process Automation in Desktop Publishing (Book): https://doi.org/10.1007/978-3-658-39375-5

Votes

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
Community Beginner ,
Nov 03, 2023 Nov 03, 2023

Copy link to clipboard

Copied

You're a genius! I really appreciate your help.

Votes

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
Community Expert ,
Nov 03, 2023 Nov 03, 2023

Copy link to clipboard

Copied

@GNDGN, you can read ParaStyle from the TextFrame and use it for the path - no need to "force" user to change it manually every time.

 

Votes

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
Community Expert ,
Nov 03, 2023 Nov 03, 2023

Copy link to clipboard

Copied

@GNDGN  I'm sorry to say - but you are doing the same - wrong thing - again. 

 

You shouldn't be modifying "contents" - you should copy&paste or thread text between objects.

 

Votes

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
Community Expert ,
Nov 05, 2023 Nov 05, 2023

Copy link to clipboard

Copied

Copy/paste is best avoided. Use move or duplicate instead:

tf.parentStory.duplicate (
  LocationOptions.AFTER, 
  tp.insertionPoints[0]
);

 

Votes

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
Community Beginner ,
Nov 05, 2023 Nov 05, 2023

Copy link to clipboard

Copied

your method is not working. error string  :tp is undefined

Votes

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
Community Expert ,
Nov 05, 2023 Nov 05, 2023

Copy link to clipboard

Copied

quote

your method is not working. error string  :tp is undefined


By @Esmaeel33333501tifh

 

You should show us your whole script - because it's important where in the code you've inserted Peter's code.

 

But from the error I'm guessing in the wrong place - before the first "declaration" of "tp"...

 

Votes

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
Community Expert ,
Nov 05, 2023 Nov 05, 2023

Copy link to clipboard

Copied

That line I gave replaces the last line in GNDGN's script.

Votes

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
Community Beginner ,
Nov 05, 2023 Nov 05, 2023

Copy link to clipboard

Copied

LATEST

i replace the line you gave with the last line in it is working. no need to apply paragraph style anymore. thanks

Votes

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