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

Looking Illustrator script: To write Document title at selected text frame

Engaged ,
Feb 19, 2024 Feb 19, 2024

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

jkhakase_0-1708357465301.png

 

TOPICS
How-to , Scripting

Views

560

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

Community Expert , Feb 21, 2024 Feb 21, 2024

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();

Votes

Translate

Translate
Adobe
Community Expert ,
Feb 19, 2024 Feb 19, 2024

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();

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
Engaged ,
Feb 19, 2024 Feb 19, 2024

Copy link to clipboard

Copied

Thank you so much, Its working perfectly as I want. saved many clicks

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
Community Expert ,
Feb 20, 2024 Feb 20, 2024

Copy link to clipboard

Copied

Kurt are you scripting now? Welcome to the club!!! 

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
Community Expert ,
Feb 20, 2024 Feb 20, 2024

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.

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
Engaged ,
Feb 20, 2024 Feb 20, 2024

Copy link to clipboard

Copied

@Kurt Gold can we write Resepective Artobard Number at selected text frame ?

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
Community Expert ,
Feb 21, 2024 Feb 21, 2024

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?

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
Engaged ,
Feb 22, 2024 Feb 22, 2024

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 

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
Community Expert ,
Feb 22, 2024 Feb 22, 2024

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();

 

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
Engaged ,
Feb 23, 2024 Feb 23, 2024

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

jkhakase_0-1708682992695.png

 

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
Community Expert ,
Feb 23, 2024 Feb 23, 2024

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.

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
Community Expert ,
Feb 24, 2024 Feb 24, 2024

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();

 

 

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
Engaged ,
Feb 25, 2024 Feb 25, 2024

Copy link to clipboard

Copied

LATEST

Really awesome!, working perectly as per custom need. Thank you so much

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
Engaged ,
Feb 21, 2024 Feb 21, 2024

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.

jkhakase_0-1708511474428.png

 

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
Community Expert ,
Feb 21, 2024 Feb 21, 2024

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();

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
Engaged ,
Feb 21, 2024 Feb 21, 2024

Copy link to clipboard

Copied

Thank you again, Amezing!, working perfectly 🙂

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