Copy link to clipboard
Copied
Dear Friends,
Looking a script to write document title at my prepared and selected text frame. this will be great help on creating multiple documents from the template.
I browse on net getting many script to write doc title at various position. but I am expecting it at my selected/prepared text-frame
below is the screenshot
As for the selection issue, you may take this instead.
function dt() {
var doc = app.activeDocument;
var documentTitle = doc.name.split('.')[0];
for (var i = 0; i < doc.textFrames.length; i++) {
var textFrame = doc.textFrames[i];
if (textFrame.selected) {
if (textFrame.kind === TextType.POINTTEXT || textFrame.kind === TextType.AREATEXT) {
textFrame.contents = documentTitle;
}
}
}
}
dt();
Copy link to clipboard
Copied
You may try this.
function dt() {
var doc = app.activeDocument;
var documentTitle = doc.name.split('.')[0];
for (var i = 0; i < doc.textFrames.length; i++) {
var textFrame = doc.textFrames[i];
if (textFrame.kind === TextType.POINTTEXT || textFrame.kind === TextType.AREATEXT) {
textFrame.contents = documentTitle;
}
}
}
dt();
Copy link to clipboard
Copied
Thank you so much, Its working perfectly as I want. saved many clicks
Copy link to clipboard
Copied
Kurt are you scripting now? Welcome to the club!!!
Copy link to clipboard
Copied
Carlos, I always tried to do some scripting for rather simple things and mainly for personal use.
Of course, for the complicated stuff I still prefer making bumpy actions.
Copy link to clipboard
Copied
@Kurt Gold can we write Resepective Artobard Number at selected text frame ?
Copy link to clipboard
Copied
Do you mean only the artboard number? Or the artboard name as well? Or both?
Also, is this a request for a separate script or are you looking for an addition that combines the previous script with some more information?
Copy link to clipboard
Copied
Only the respective Artboard Number, as you done for Document title. whever I will create/select the text frame based on my custom formatting
Copy link to clipboard
Copied
This should work. Note that the artboard on which the selected type objects are located has to be activated.
function artboardnumber() {
var doc = app.activeDocument;
if (doc && doc.artboards.length > 0) {
var activeArtboardIndex = doc.artboards.getActiveArtboardIndex();
var artboardNumber = activeArtboardIndex + 1;
for (var i = 0; i < doc.textFrames.length; i++) {
var textFrame = doc.textFrames[i];
if (textFrame.selected) {
if (textFrame.kind === TextType.POINTTEXT || textFrame.kind === TextType.AREATEXT) {
textFrame.contents = artboardNumber;
}
}
}
}
}
artboardnumber();
Copy link to clipboard
Copied
It is working for single artbaord at single text frame only, When I select text frame at multiple artboards and run the script, Its not generated the Respective Artboard Number. as shown below
Copy link to clipboard
Copied
Yes, I already mentioned that in my previous post.
Of course, you could modify the script to get the desired behaviour as per your screenshot above.
Copy link to clipboard
Copied
Or you may try this attempt.
function anAll() {
var doc = app.activeDocument;
if (!doc || doc.artboards.length === 0) {
return;
}
for (var i = 0; i < doc.textFrames.length; i++) {
var textFrame = doc.textFrames[i];
if (textFrame.selected && !textFrame.locked &&
(textFrame.kind === TextType.POINTTEXT || textFrame.kind === TextType.AREATEXT)) {
var artboardNumber = getArtboardNumber(textFrame);
if (artboardNumber !== -1) {
textFrame.contents = artboardNumber.toString();
}
}
}
}
function getArtboardNumber(textFrame) {
var doc = app.activeDocument;
var textFrameBounds = textFrame.geometricBounds;
for (var i = 0; i < doc.artboards.length; i++) {
var artboardRect = doc.artboards[i].artboardRect;
if (textFrameBounds[0] >= artboardRect[0] &&
textFrameBounds[1] <= artboardRect[1] &&
textFrameBounds[2] <= artboardRect[2] &&
textFrameBounds[3] >= artboardRect[3]) {
return i + 1;
}
}
return -1;
}
anAll();
Copy link to clipboard
Copied
Really awesome!, working perectly as per custom need. Thank you so much
Copy link to clipboard
Copied
Hi @Kurt Gold
Recently I Observed that this script is working at none selected text frame as well, and It replace all the text frame with document title. below is the screenshot of it. could you please check where is the issue.
Copy link to clipboard
Copied
As for the selection issue, you may take this instead.
function dt() {
var doc = app.activeDocument;
var documentTitle = doc.name.split('.')[0];
for (var i = 0; i < doc.textFrames.length; i++) {
var textFrame = doc.textFrames[i];
if (textFrame.selected) {
if (textFrame.kind === TextType.POINTTEXT || textFrame.kind === TextType.AREATEXT) {
textFrame.contents = documentTitle;
}
}
}
}
dt();
Copy link to clipboard
Copied
Thank you again, Amezing!, working perfectly 🙂