Copier le lien dans le Presse-papiers
Copié
I'm looking for a way to record (add) a characterStyle from one textItem and apply it to another. I haven't done much with character scripting so I'm really not sure where to start.
var idoc = app.activeDocument;
//loop through characterAttributes to get and add current selected style?
doc.characterStyles.add("MyStyle");
selected = idoc.selection;
//Select and Apply to selected text
idoc.characterStyles.getByName("MyStyle").applyTo( selected );
Salut !
Il faut faire un choix parmi les propriétés de characterAttributes,
pour moi une boucle n'est pas possible...
...// JavaScript Document for Illustrator
var docRef = activeDocument;
var text = selection[0]; alert(text.contents);
var charStyle = docRef.characterStyles.add("copy");
var charAttr = charStyle.characterAttributes;
with (text.textRange) {
charAttr.size = characterAttributes.size;
charAttr.verticalScale = characterAttributes.verticalScale;
charAttr.horizontalScale = chara
Copier le lien dans le Presse-papiers
Copié
Hi,
I think that you should use:
selected = idoc.selection[0];
of course if you have selected over 1 item, you should use loop for it.
Copier le lien dans le Presse-papiers
Copié
I use followed code for that:
var charStyle = doc.characterStyles.add("style");
var charAttr = charStyle.characterAttributes;
var paraAttr_0 = t.paragraphs[0].paragraphAttributes;
paraAttr_0.justification = Justification.CENTER;
var kolor2 = new CMYKColor();
kolor2.cyan = 0;
kolor2.magenta = 100;
kolor2.yellow = 0;
kolor2.black = 0;
charAttr.fillColor = kolor2;
charAttr.justification = Justification.CENTER;
charStyle.applyTo(t.textRange);
Copier le lien dans le Presse-papiers
Copié
Salut !
Il faut faire un choix parmi les propriétés de characterAttributes,
pour moi une boucle n'est pas possible...
// JavaScript Document for Illustrator
var docRef = activeDocument;
var text = selection[0]; alert(text.contents);
var charStyle = docRef.characterStyles.add("copy");
var charAttr = charStyle.characterAttributes;
with (text.textRange) {
charAttr.size = characterAttributes.size;
charAttr.verticalScale = characterAttributes.verticalScale;
charAttr.horizontalScale = characterAttributes.horizontalScale;
charAttr.capitalization = characterAttributes.capitalization;
charAttr.fillColor = characterAttributes.fillColor;
charAttr.textFont = characterAttributes.textFont;
}
var textRef1 = docRef.textFrames.add();
textRef1.contents = "Scripting is fun!";
textRef1.top = -700;
textRef1.left = 50;
charStyle.applyTo(textRef1.textRange);
de elleere
Copier le lien dans le Presse-papiers
Copié
thank you renél! You are awesome.
Copier le lien dans le Presse-papiers
Copié
One more question. What am I doing wrong here?? Trying to apply style to selected text. For some reason this works sometimes but not every time.
var idoc = app.activeDocument;
var text = selection[0];
idoc.characterStyles.getByName( 'BNumber' ).applyTo( text.textRange );
Copier le lien dans le Presse-papiers
Copié
Bonjour Jeremy,
Quand tu appliques manuellement un style à un texte, tu as souvent un
petit signe + qui t'indique que le style n'est pas appliqué
complètement.
Il faut alors cliquer sur le +
avec le script c'est la même chose.
Il faut donc ajouter le Boolean [,clearingOverrides = true]
var idoc = app.activeDocument;
var text = selection[0];
idoc.characterStyles.getByName('copy').applyTo(text.textRange,true);
de elleere
Copier le lien dans le Presse-papiers
Copié
I found this last night. Thanks for all your help Renel.
Copier le lien dans le Presse-papiers
Copié
function findNote( note , toApply ){
var idoc = app.activeDocument;
var text = selection[0];
for (var i = 0; i < idoc.pageItems.length; i++) {
pageItemNote = idoc.pageItems;
if(pageItemNote.note == note){
idoc.selection = pageItemNote;
alert(note + " " + toApply);
idoc.characterStyles.getByName(toApply).applyTo( text.textRange, true );
activeDocument.selection = null;
}
}
};
var LnFront = 'Front Text';
var LnBack = 'Back Text';
var PnFront = 'FText';
var PnBack = 'BText';
findNote(LnFront , PnFront);
findNote(LnBack , PnBack);
Can someone tell me what I am missing here. The runs only the first function "findNote(LnFront, PnFront)", then when run again "findNote(LnBack, PnBack)" tells me the selected is not an object. But is selected as well the correct characterStyle name ??
Copier le lien dans le Presse-papiers
Copié
Salut Jeremy,
What is it ???
if(pageItemNote.note == note){
idoc.selection = pageItemNote;
Copier le lien dans le Presse-papiers
Copié
This selects the text needed to apply the characterStyle.
This is what I worked on today. The selection of the text item happens but it looks like the characterStyles are being applied before the selection takes place. Any help would be greatly appreciated.
function findAndApply( textName , toApply ){
var idoc = app.activeDocument;
var sel = selection[0];
for (var i = 0; i < idoc.pageItems.length; i++) {
pageItemNote = idoc.pageItems.note;
if (pageItemNote == textName) {
idoc.pageItems[textName].selected = true;
idoc.characterStyles.getByName(toApply).applyTo( sel.textRange, true );
}
}
};
findAndApply("Front Text" , "Ftext");
Copier le lien dans le Presse-papiers
Copié
Salut Jeremy,
Tu mélanges tout, il faut étudier la documentation fournie par Adobe, je te donne un lien pour télécharger le pdf.
de elleere
Copier le lien dans le Presse-papiers
Copié
I think I just needed a refresher. The selection needed to be made a second time before applying. Thanks for your help.
Trouvez plus d’idées, d’événements et de ressources dans la nouvelle communauté Adobe
Explorer maintenant