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

Script to change the color of the selected texts that grouped

Explorer ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

Hello Everyone,

 

I have  the script to change the color of the text in the selected text frame.

 

But, sometimes in my file certain textframes are grouped together, at that time this script  doesn't change the color of the text in  grouped text frames.

 

Someone would help to figure out this situation.

 

I am attaching the code that worked for the non grouped text frames.

docRef = app.activeDocument;

var selectedObjects = docRef.selection;

var color1 = new CMYKColor();
color1.cyan = 100;
color1.magenta = 0;
color1.yellow = 0;
color1.black = 0;
var spot = docRef.spots.add();
spot.color = color1;
spot.colorType = ColorModel.SPOT;
spot.name = "Keyline Blue";

for (var i = 0; i < selectedObjects.length; i++) {
    if (selectedObjects[i].typename == "TextFrame") {
        selectedObjects[i].textRange.fillColor = keyline.color;
    }
}

 

TOPICS
Scripting

Views

243

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 , Aug 12, 2022 Aug 12, 2022

Below is the version for the selected objects only. This version will change color for all selected textframes that are grouped or ungrouped.

docRef = app.activeDocument;

var color1 = new CMYKColor();
color1.cyan = 100;
color1.magenta = 0;
color1.yellow = 0;
color1.black = 0;
var spot = docRef.spots.add();
spot.color = color1;
spot.colorType = ColorModel.SPOT;
spot.name = "Keyline Blue";

var selectedObjects = docRef.selection;

for (var i = 0; i < selectedObjects.length; i++) {
    if (selecte
...

Votes

Translate

Translate
Adobe
Community Expert ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

Try the following version

docRef = app.activeDocument;

var color1 = new CMYKColor();
color1.cyan = 100;
color1.magenta = 0;
color1.yellow = 0;
color1.black = 0;
var spot = docRef.spots.add();
spot.color = color1;
spot.colorType = ColorModel.SPOT;
spot.name = "Keyline Blue";

var _groupItems = docRef.groupItems;
for (var g = 0; g < _groupItems.length; g++) {
    for (var t = 0; t < _groupItems[g].textFrames.length; t++) {
        _groupItems[g].textFrames[t].textRange.fillColor = spot.color;
    }
}

 

I was getting an error in your code at keyline.color beacuse keyline is undefined, Therefore change to spot.color

Best regards

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
Explorer ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

Hi Charu Rajput,

 

Your script will change the grouped text frames in the entired document. but i want to apply the script to the selected grouped text frames in the illustrator file.

 

I just want to change the selected textframes that are grouped.

 

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 ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

Below is the version for the selected objects only. This version will change color for all selected textframes that are grouped or ungrouped.

docRef = app.activeDocument;

var color1 = new CMYKColor();
color1.cyan = 100;
color1.magenta = 0;
color1.yellow = 0;
color1.black = 0;
var spot = docRef.spots.add();
spot.color = color1;
spot.colorType = ColorModel.SPOT;
spot.name = "Keyline Blue";

var selectedObjects = docRef.selection;

for (var i = 0; i < selectedObjects.length; i++) {
    if (selectedObjects[i].typename == "TextFrame") {
        selectedObjects[i].textRange.fillColor = spot.color;
    } else if (selectedObjects[i].typename == "GroupItem") {
        for (var t = 0; t < selectedObjects[i].textFrames.length; t++) {
            selectedObjects[i].textFrames[t].textRange.fillColor = spot.color;
        }
    }
}

 

Best regards

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
Explorer ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

Hi Charu Rajput,

 

I found the idea and written the script, please refer below,

 

docRef = app.activeDocument;

var selectedObjects = docRef.selection;

var color1 = new CMYKColor();
color1.cyan = 100;
color1.magenta = 0;
color1.yellow = 0;
color1.black = 0;
var spot = docRef.spots.add();
spot.color = color1;
spot.colorType = ColorModel.SPOT;
spot.name = "Keyline Blue";

var keyline = docRef.swatches.getByName('Keyline Blue');

for (var i = 0; i < selectedObjects.length; i++) {
    if (selectedObjects[i].typename == "GroupItem") {
    for (var t = 0; t < selectedObjects[i].textFrames.length; t++) {
        selectedObjects[i].textFrames[t].textRange.fillColor = keyline.color;

}
	}
	
}

Thanks for your response

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 ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

@Surya24 

Your script will not work, if textframe is selected which is outside the group. Your version will work only on the selected textframes that are inside the group. Not on outside the group. If this is your requirement then your script is perfect!.

 

Best regards

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
Explorer ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

Yeah, Charu Rajput, my most of the text will be there grouped only. Also thanks a lot for your support.

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
Guide ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

LATEST

 

var docRef = app.activeDocument;
var selectedObjects = docRef.selection;
var color1 = new CMYKColor();
color1.cyan = 100;
color1.magenta = 0;
color1.yellow = 0;
color1.black = 0;
var spot = docRef.spots.add();
spot.color = color1;
spot.colorType = ColorModel.SPOT;
spot.name = "Keyline Blue";
var keyline = docRef.swatches.getByName('Keyline Blue');
var array = [];
recurse(selectedObjects);
function recurse(items) {
    for (var i = 0; i < items.length; i++) {
        if (items[i].typename == "TextFrame") {
            array.push(items[i]);
        } else {
            recurse(items[i].pageItems);
        }
    }
}
for (var i = 0; i < array.length; i++) {
    array[i].textRange.fillColor = keyline.color;
}

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