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

What is the method to identify which column a certain character style is in?

Advocate ,
Jan 24, 2024 Jan 24, 2024

Copy link to clipboard

Copied

What is the method to search for a certain character style (such as Character Style AAA), identify its A, B, or C columns in two (or three) columns, and then apply Character Style A, Character Style B, and Character Style C respectively

 

The manual workload is too heavy, help~ please 

Thank you.

 

6600.jpg

TOPICS
Bug , Experiment , Feature request , How to , Scripting

Views

207

Translate

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 , Jan 24, 2024 Jan 24, 2024

Determining the column index of some text is something that comes back regularly. In this case, to apply a character style to some text based on its column index can be done as follows:

 

cstyles = [
  app.activeDocument.characterStyles.item('A'),
  app.activeDocument.characterStyles.item('B'),
  app.activeDocument.characterStyles.item('C'),
];

app.findGrepPreferences = null;
app.findGrepPreferences.appliedCharacterStyle  
  = app.activeDocument.characterStyles.item ('AAA');
  
instances = app.
...

Votes

Translate

Translate
Community Expert ,
Jan 24, 2024 Jan 24, 2024

Copy link to clipboard

Copied

Look intzthe paragraph and character style panels. 

why do you not work with paragraph styles?

Why do you use additional returns to force space between paragraphs?

Votes

Translate

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 Expert ,
Jan 24, 2024 Jan 24, 2024

Copy link to clipboard

Copied

Determining the column index of some text is something that comes back regularly. In this case, to apply a character style to some text based on its column index can be done as follows:

 

cstyles = [
  app.activeDocument.characterStyles.item('A'),
  app.activeDocument.characterStyles.item('B'),
  app.activeDocument.characterStyles.item('C'),
];

app.findGrepPreferences = null;
app.findGrepPreferences.appliedCharacterStyle  
  = app.activeDocument.characterStyles.item ('AAA');
  
instances = app.activeDocument.findGrep();

for (i = 0; i < instances.length; i++) {
  columnIndex = instances[i].parentStory.insertionPoints.itemByRange (
    instances[i].parentTextFrames[0].insertionPoints[0].index,
    instances[i].index
  ).textColumns.length-1;
  instances[i].appliedCharacterStyle = cstyles[columnIndex];
}

 

In other words, you count the number of columns between the parent frame's first insertion point and the text's first insertion point. (The script can be made more efficient by working story by story, but that doesn't change the basic principle of getting a column index.)

Votes

Translate

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
Advocate ,
Jan 24, 2024 Jan 24, 2024

Copy link to clipboard

Copied

Hi~Peter Kahrel

This script is too good. It's working

I can only say that you are too great.

Thank you very, very much

Votes

Translate

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
Advocate ,
Dec 17, 2024 Dec 17, 2024

Copy link to clipboard

Copied

@Peter Kahrel 

Hello, Peter Kahrel.
This script is now suggesting an error.

The same file that worked a year ago works using it.
Help to see it. Thank you very much.

696.jpg

Votes

Translate

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 Expert ,
Dec 17, 2024 Dec 17, 2024

Copy link to clipboard

Copied

Do the four referenced character styles (A, B, C, AAA) still exist?

Votes

Translate

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
Advocate ,
Dec 17, 2024 Dec 17, 2024

Copy link to clipboard

Copied

A B C AAA styles are available

I just made a test sample, and it still gives me an error.

The file is attached.

Votes

Translate

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 Expert ,
Dec 17, 2024 Dec 17, 2024

Copy link to clipboard

Copied

You are wrong: character style AAA is not available. Rename @ to AAA and the script runs as expected.

 

PeterKahrel_0-1734449987326.png

 

Votes

Translate

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
Advocate ,
Dec 17, 2024 Dec 17, 2024

Copy link to clipboard

Copied

God, it's been so long since I've used it that I've memorized it as AAA being a paragraph style.
Also didn't observe that sometime the script had actually run silently.
I forgot, I was waiting for it to pop up the dialog ......
I'll make a note of that.


Thank you so much, you're genuinely great.

Votes

Translate

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
Advocate ,
Dec 17, 2024 Dec 17, 2024

Copy link to clipboard

Copied

Is it possible to convert only paragraph styles and no character styles?only.jpg

Votes

Translate

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 Expert ,
Dec 17, 2024 Dec 17, 2024

Copy link to clipboard

Copied

LATEST

Sure. Replace these two lines:

app.findGrepPreferences.appliedCharacterStyle  
  = app.activeDocument.characterStyles.item ('AAA');

with

app.findGrepPreferences.appliedParagraphStyle  
  = app.activeDocument.paragraphStyles.item ('AAA');

Votes

Translate

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