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

Avoid to apply character style

Participant ,
Jul 21, 2017 Jul 21, 2017

Hi,

I have these lines that applied the style "bold" to my words:

var myDocument = app.activeDocument;

var myStyle = myDocument.characterStyles.itemByName("bold");

myDocument.pages[0].textFrames[0].paragraphs.everyItem().applyCharacterStyle(myStyle, false);

But how to avoid and not apply in words that already have other style applied?

I think this is so easy, but I'm a novice.

TOPICS
Scripting
648
Translate
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
Enthusiast ,
Jul 21, 2017 Jul 21, 2017

First of all, why the hell are you applying character style to an entire

paragraph? LoL...

Use paragraph style. Maybe with a grep style to apply the bold or any other

charStyle to the words you want.

Translate
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
Participant ,
Jul 21, 2017 Jul 21, 2017

Na verdade eu queria só entender como fazer pra ele desconsiderar uma palavra que já está com estilo aplicado e não aplicar e adaptar no código que estou fazendo:

myDoc.colors.add({name:"marcação", colorValue:[3,73,100,0], space:ColorSpace.CMYK, model:ColorModel.PROCESS});

var myMenu = app.menuActions.item('Verificar ortografia...');

var resultado;

for(var i = 1; i <= 1000; i++){

 

myMenu.invoke();

app.selection[0].underline = true;

app.selection[0].underlineColor = "marcação";

app.selection[0].underlineWeight = 10;

app.selection[0].underlineOffset = -3;

if(i==1){

    resultado=app.selection[0];

}else if(resultado===app.selection[0]){

    break;

}

}

Ele abre o Verificador de ortografia e com a palavra selecionada aplica as propriedades de sublinhado e assim sucessivamente até voltar pra primeira que aplicou. Só que não quero que aplique se a palavra já estiver com um estilo de caractere aplicado e passe pra próxima.

É isso.. =P

Achei melhor explicar em português.

Translate
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
Enthusiast ,
Jul 21, 2017 Jul 21, 2017

Faz um if pra ver se a palavra está com algum estilo de caractere aplicado.

Se o estilo aplicado for , aplica o que tu quer. Se for diferente de

, ou seja, algum outro charStyle, não faz nada.

Sacou?

Translate
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
Participant ,
Jul 21, 2017 Jul 21, 2017

A teoria de que fosse do jeito que você explicou eu já imaginava. Não consigo é passar isso pro código, esse que eu fiz foi pesquisando e muito pra poder montar.

A parte de "não fazer nada" ainda não sei como escreve e também vai ser mais difícil pois é apenas um estilo de caractere do meu documento que quero que ele evite aplicar, nos outros vai poder.

Translate
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
Enthusiast ,
Jul 21, 2017 Jul 21, 2017

Não entendi...

Translate
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 Expert ,
Jul 21, 2017 Jul 21, 2017

You can test if a character style already has been applied by reading it. Beware, I'm typing on an iPad and from memory.

   chStyle = app.selection[0].appliedCharacterStyle;

   alert (chStyle.name);

The last line will fail if the style is empty, so test for that:

   if (chStyle == app.activeDocument.characterStyles.item(0))

       .. no style applied ..

Furthermore, reading "the" style from a selection will fail with an error if there are more than one style applied to it. In the user interface, this would be indicated by an empty field; JavaScript just stops with an error. You could inspect the formatting ranges of your selection (I can't recall the exact property name right away), but it may be easier to just add a try ... catch around the test. If it fails, you are sure there is at least one style applied to it, somewhere. If it succeeds, test if the result is "None".

Translate
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
Participant ,
Jul 21, 2017 Jul 21, 2017
LATEST

Thank you for your attention and patience.

I solved my problem using the Find/Change in the end of the script to reset the specific style.

Translate
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