• 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?

Advisor ,
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

275

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
Advisor ,
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
Advisor ,
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
Advisor ,
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
Advisor ,
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
Advisor ,
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

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

Copy link to clipboard

Copied

Here's the script by Peter Kahrel from the forums

I use this script to label specific characters on different columns with ABC.


The same file was available for use a year ago.

Now suddenly it prompts an error.

 

Some scripts will not work after ID upgrade?
Help to see it. Thank you very much.

 

Initial address:

https://community.adobe.com/t5/indesign-discussions/what-is-the-method-to-identify-which-column-a-ce... 

696.jpg

 

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];
}

 

 

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 26, 2024 Dec 26, 2024

Copy link to clipboard

Copied

Looking at the error line the thing that could be an issue according to me is either the character style does not exist or there is some issue with the name of the character style.

-Manan

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 26, 2024 Dec 26, 2024

Copy link to clipboard

Copied

This discussion was locked because it repeated another one, where the correct answer was given. I don't know what happened to the note I left here that pointed that out.

Anyway, it shows that your answer is correct, @Manan Joshi ðŸ™‚

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 26, 2024 Dec 26, 2024

Copy link to clipboard

Copied

Ahh, now I notice the locked icon. However, no note present. Ideally I would have merged this to the original post or rather marked it for deletion as a duplicate.

-Manan

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 27, 2024 Dec 27, 2024

Copy link to clipboard

Copied

LATEST

Yep, that's what I should have done.

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