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

Changer le style de police d'un texte avec javascript

Community Beginner ,
Feb 09, 2023 Feb 09, 2023

Copy link to clipboard

Copied

Bonjour à tous,

J'ai un script qui ouvre une boite de dialogue pour que je puiise entrer le texte que je souhaite afficher à un endroit spécifique de mon plan de travail. Tout fonctionne sauf que je n'arive pas à changer le style de police de mon texte.. J'aimerais que le texte soit en police "Myriad pro" et en style de police "Bold" et que la taille de la police soit de 14 pt.

Voici le script que j'utilise

var text = prompt("Entrez le texte à écrire:", "");

if (text) {
  var doc = app.activeDocument;
 
  var layer = doc.layers.getByName("FOND DE PLAN");
  layer.locked = false;
 
  var textFrame = layer.textFrames.add();
  textFrame.contents = text;
  textFrame.textRange.characterAttributes.font = "Myriad Pro Bold";
  textFrame.textRange.characterAttributes.fontWeight = "Bold";
 
  var nonPrintableLayer = doc.layers.getByName("NON IMPRIMABLE");
  var pointOfGathering = nonPrintableLayer.pathItems.getByName("POINT DE RASSEMBLEMENT");
 
  var textBounds = textFrame.geometricBounds;
  var pointBounds = pointOfGathering.geometricBounds;
 
  var x = pointBounds[0] + (pointBounds[2] - pointBounds[0] - textBounds[2] + textBounds[0]) / 2;
  var y = pointBounds[1] + (pointBounds[3] - pointBounds[1] - textBounds[3] + textBounds[1]) / 2;
 
  textFrame.left = x;
  textFrame.top = y;
 
  layer.locked = true;
}



TOPICS
Scripting , Third party plugins , Tools

Views

554
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 09, 2023 Feb 09, 2023

characterAttributes.font is not part of the API, you should use

characterAttributes.textFont

 

characterAttributes.fontWeight is not part of the API

 

= "Myriad Pro Bold"; you can't assign the font by providing the String name, you need to get the Font Object and use the internal name illustrator understands

textFonts.getByName(Internal_fontname);

 

 

var text = prompt("Entrez le texte à écrire:", "");

if (text) {
    var fontname = "MyriadPro-Bold";
  var doc = app.activeDocument;
 
  var laye
...

Votes

Translate
Adobe
Community Expert ,
Feb 09, 2023 Feb 09, 2023

Copy link to clipboard

Copied

characterAttributes.font is not part of the API, you should use

characterAttributes.textFont

 

characterAttributes.fontWeight is not part of the API

 

= "Myriad Pro Bold"; you can't assign the font by providing the String name, you need to get the Font Object and use the internal name illustrator understands

textFonts.getByName(Internal_fontname);

 

 

var text = prompt("Entrez le texte à écrire:", "");

if (text) {
    var fontname = "MyriadPro-Bold";
  var doc = app.activeDocument;
 
  var layer = doc.layers.getByName("FOND DE PLAN");
  layer.locked = false;
 
  var textFrame = layer.textFrames.add();
  textFrame.contents = text;
  textFrame.textRange.characterAttributes.textFont = textFonts.getByName(fontname); 
 
  var nonPrintableLayer = doc.layers.getByName("NON IMPRIMABLE");
  var pointOfGathering = nonPrintableLayer.pathItems.getByName("POINT DE RASSEMBLEMENT");
 
  var textBounds = textFrame.geometricBounds;
  var pointBounds = pointOfGathering.geometricBounds;
 
  var x = pointBounds[0] + (pointBounds[2] - pointBounds[0] - textBounds[2] + textBounds[0]) / 2;
  var y = pointBounds[1] + (pointBounds[3] - pointBounds[1] - textBounds[3] + textBounds[1]) / 2;
 
  textFrame.left = x;
  textFrame.top = y;
 
  layer.locked = true;
}

 

 

Votes

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 Beginner ,
Feb 09, 2023 Feb 09, 2023

Copy link to clipboard

Copied

LATEST

Thank you so much @CarlosCanto !!!

Votes

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