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;
}
}
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
...
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
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.
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;
}
}
}
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
Copy link to clipboard
Copied
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!.
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.
Copy link to clipboard
Copied
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;
}