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

Auto add text to a path

Community Beginner ,
Nov 01, 2023 Nov 01, 2023

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
843
Translate
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

 

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.

Translate
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

 

____________________
Robotic Process Automation in Desktop Publishing (Book): https://doi.org/10.1007/978-3-658-39375-5
Translate
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

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

Translate
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

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?

Translate
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

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
Translate
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

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

Translate
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

@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.

 

Translate
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

@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.

 

Translate
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/paste is best avoided. Use move or duplicate instead:

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

 

Translate
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

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

Translate
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
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"...

 

Translate
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

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

Translate
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
LATEST

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

Translate
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