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

Extendscript - search string and change character style

New Here ,
Nov 15, 2024 Nov 15, 2024

This script is meant to change in each paragraph, the characters after the "," to a smaller character style.

It's not functioning as designed. Currently I can get it to count the characters but the "Start_changing" variable never changes from zero. Basically I have the possibility of 6 names in a list, all with alphabet soup after the comma and before the return. Any help would be greatly appreciated.

 

// --- person's degree in smaller font

var HealthNameBlock;
HealthNameBlock = InDesign_Document.layers.item("nameblock").textFrames.item(0);

var HealthAddressBlock;
HealthAddressBlock = InDesign_Document.layers.item("addressblock").textFrames.item(0);

var HealthNameStory;
HealthNameStory = HealthNameBlock.parentStory;

var Start_changing;
Start_changing = 0;

var Paragraph_character_counter;

var Story_character_counter;

if(HealthNameStory.paragraphs.count() > 0)
{
for(Paragraph_counter = 0 ; Paragraph_counter < HealthNameStory.paragraphs.count() ; Paragraph_counter++)
{
for(Paragraph_character_counter = 0 ; Paragraph_character_counter < HealthNameStory.paragraphs.item(Paragraph_counter).characters.count() ; Paragraph_character_counter++)
{
if(HealthNameStory.paragraphs.item(Paragraph_counter).characters.item(Paragraph_character_counter).contents == "," && Start_changing == 0 && HealthNameStory.paragraphs.item(Paragraph_counter).characters.item(Paragraph_character_counter).appliedParagraphStyle == "Name")
{
Start_changing = Paragraph_character_counter + 1;
};
};
};
};

if(Start_changing > 0 )
{
for(Story_character_counter = Start_changing ; Story_character_counter < HealthNameStory.paragraphs.item(Paragraph_counter).characters.count() ; Story_character_counter++)
{
if(HealthNameStory.paragraphs.item(Paragraph_counter).characters.item(Story_character_counter).appliedParagraphStyle == "Name")
{
HealthNameStory.paragraphs.item(Paragraph_counter).characters.item(Story_character_counter).appliedCharacterStyle = InDesign_Document.characterStyles.item("degree_smalltext");
};
};
};

TOPICS
Scripting
744
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 ,
Nov 15, 2024 Nov 15, 2024
LATEST

Too early for me to dissect that code, but you can just use a GREP style in your name Paragraph Style definition. 

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