Copy link to clipboard
Copied
I need a script that makes the following changes: Change all "QUIRKY SPRING" fonts (assorted sizes) to the "Boldenvan" font (size 35). With this change, I need all changed boxes to apply the "height and width (keep proportions)" option to these changed text boxes. And finally, these changed boxes change the color to "C=69 M=46 Y=85 K=46".
I have:
var myDoc = app.activeDocument;
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
// Find ant change fonts
app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences.appliedFont = app.fonts.item("QUIRKY SPRING"); //oldfont
app.changeTextPreferences.appliedFont = app.fonts.item("BoldenVan"); //new font
myDoc.changeText();
// Change size to 35pt in new fonts
var newTextFrames = myDoc.textFrames.everyItem().texts.everyItem().appliedFont.name === "BoldenVan";
for (var i = 0; i < newTextFrames.length; i++) {
newTextFrames[i].pointSize = 35;
}
But the part of change size not function!
help?
Should be:
newTextFrames[i].texts[0].pointSize = 35;
Hi @eusoujpg , Try this—for the fill color you have to create or reference an existing swatch, in this case I did not assume the swatch exists:
var d = app.activeDocument;
//create a fill color swatch if it does not exist
var fc = makeSwatch(d, "C=69 M=46 Y=85 K=46");
fc.properties = {model:ColorModel.PROCESS, space:ColorSpace.CMYK, colorValue:[69,46,85,46]}
app.findTextPreferences = app.changeTextPreferences = app.findChangeTextOptions = null;
app.findTextPreferences.appliedFont = app.font
Copy link to clipboard
Copied
Should be:
newTextFrames[i].texts[0].pointSize = 35;
Copy link to clipboard
Copied
I'll try. Thanks! Would you have any suggestions for applying the color ("C=69 M=46 Y=85 K=46") to these "boldenvan" fonts that I'm going to change? And how would you apply the "height and width (keep proportions)" so the box doesn't burst?
Copy link to clipboard
Copied
I'm not JS guy and I'm replying from my crappy phone - so can't give you working code - but I would suggest, that instead of applying local overrides "one at a time" - you should create and apply ObjectStyle.
Something like:
newTextFrames[i].appliedObjectStyle = myDoc.objectStyles("my style");
Instead of the line with "= 35;"
Copy link to clipboard
Copied
*Seems* like something that needs little more than Find/Change, perhaps in GREP mode... but as you have the script, that's a valid approach, too.
Copy link to clipboard
Copied
Hi @eusoujpg , Try this—for the fill color you have to create or reference an existing swatch, in this case I did not assume the swatch exists:
var d = app.activeDocument;
//create a fill color swatch if it does not exist
var fc = makeSwatch(d, "C=69 M=46 Y=85 K=46");
fc.properties = {model:ColorModel.PROCESS, space:ColorSpace.CMYK, colorValue:[69,46,85,46]}
app.findTextPreferences = app.changeTextPreferences = app.findChangeTextOptions = null;
app.findTextPreferences.appliedFont = app.fonts.item("QUIRKY SPRING"); //oldfont
var res = app.activeDocument.findText();//returns an array of found texts
for (var i = 0; i < res.length; i++){
res[i].appliedFont = app.fonts.item("BoldenVan");
res[i].pointSize = 35
res[i].parentTextFrames[0].fillColor = fc;
res[i].parentTextFrames[0].textFramePreferences.autoSizingType = AutoSizingTypeEnum.HEIGHT_AND_WIDTH_PROPORTIONALLY
};
/**
* Makes a new named Swatch
* @ param the document to add the color to
* @ param color name
* @ return the new swatch
*/
function makeSwatch(d, n){
if (d.colors.itemByName(n).isValid) {
return d.colors.itemByName(n);
} else {
return d.colors.add({name:n});
}
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
It‘s probably because the point size change is causing the text to overflow. Try this, it gets the text frame object before changing anything:
var d = app.activeDocument;
//create a fill color swatch if it does not exist
var fc = makeSwatch(d, "C=69 M=46 Y=85 K=46");
fc.properties = {model:ColorModel.PROCESS, space:ColorSpace.CMYK, colorValue:[69,46,85,46]}
app.findTextPreferences = app.changeTextPreferences = app.findChangeTextOptions = null;
app.findTextPreferences.appliedFont = app.fonts.item("QUIRKY SPRING"); //oldfont
var res = app.activeDocument.findText();//returns an array of found texts
var pf;
for (var i = 0; i < res.length; i++){
pf = res[i].parentTextFrames[0]
res[i].appliedFont = app.fonts.item("BoldenVan");
res[i].pointSize = 35;
res[i].noBreak = true;
pf.fillColor = fc;
pf.textFramePreferences.autoSizingType = AutoSizingTypeEnum.HEIGHT_AND_WIDTH;
};
/**
* Makes a new named Swatch
* @ param the document to add the color to
* @ param color name
* @ return the new swatch
*/
function makeSwatch(d, n){
if (d.colors.itemByName(n).isValid) {
return d.colors.itemByName(n);
} else {
return d.colors.add({name:n});
}
}
Copy link to clipboard
Copied
Why not just apply ObjectStyle to the frame - instead of separate properties?
Then you won't have to care about anything.