Answered
@renél80416020 The script is very good, but is there a way to center multiple texts and not just a single selected text?
Regarding the red line, there's no problem; it was simply Illustrator's spell checker.
Avec les modifications:
// JavaScript Document
// center_baselineShift.js
// author Landry René
// Sun, 21 December 2025 10:42:03 GMT
/* Select a text
Center: Align with the point located halfway
between the ascender and the descender of the font*/
function main() {
if (selection.length) {
var texts = [];
extractTexts(selection,texts);
if (texts.length) {
var t, line0, dup, vect, bdDup, h;
for (var i = 0; i < texts.length; i++) {
t = texts[i];
line0 = t.lines[0];
dup = activeDocument.textFrames.add();
copieObjtextRange (line0,dup);
vect = dup.createOutline();
bdDup = vect.geometricBounds; // visibleBounds
h = bdDup[1]-bdDup[3];
vect.remove();
t.textRange.baselineShift = - h/2;
}
}
}
}
if (app.documents.length) main();
// -------
function copieObjtextRange (obj1,obj2) {
for (var j = 0; j < obj1.characters.length; j++) {
if("pjgq,;".indexOf(obj1.characters[j].contents) == -1)
obj1.characters[j].duplicate(obj2.insertionPoints[obj2.insertionPoints.length-1]);
}
}
// -------
function extractTexts(s,tabs) {
if(s.typename == "TextRange") return;
for(var i = 0; i < s.length; i++){
if(s[i].typename == "TextFrame" && s[i].locked == false){
tabs.push(s[i]);
} else if(s[i].typename == "GroupItem"){
// Cherche les objets de types TextFrame dans ce groupe, recursivement
extractTexts(s[i].pageItems, tabs);
}
}
}
// -------Sign up
Already have an account? Login
To post, reply, or follow discussions, please sign in with your Adobe ID.
Sign inSign in to Adobe Community
No account yet? Create an account
To post, reply, or follow discussions, please sign in with your Adobe ID.
Sign inEnter your E-mail address. We'll send you an e-mail with instructions to reset your password.
