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)
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:
After:
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.
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:
After:
Copy link to clipboard
Copied
I tested the code and it is functioning correctly. Nice work!
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?
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.
Copy link to clipboard
Copied
You're a genius! I really appreciate your help.
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.
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.
Copy link to clipboard
Copied
Copy/paste is best avoided. Use move or duplicate instead:
tf.parentStory.duplicate (
LocationOptions.AFTER,
tp.insertionPoints[0]
);
Copy link to clipboard
Copied
your method is not working. error string :tp is undefined
Copy link to clipboard
Copied
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"...
Copy link to clipboard
Copied
That line I gave replaces the last line in GNDGN's script.
Copy link to clipboard
Copied
i replace the line you gave with the last line in it is working. no need to apply paragraph style anymore. thanks