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

Script to change bulleted and numbered lists to text without converting the Paragraph Styles

Participant ,
Mar 27, 2023 Mar 27, 2023

I've seen a posts here about using the "Convert Bullets to Text" contextual option in text as well the method app.activeDocument.stories.everyItem().convertBulletsAndNumberingToText(); however neither is satifactory so ive been writing a script to change the copy in a document that has a bullet or number list style applied to converted text, but i'm having trouble figuring out how to script  going through the text, identifying the ones with specific paragraph styles ( there are 6 styles, all set within two layers of groupings: Body Styles [group] > Lists [group] > Bullet lvl 1 [style].

heres what ive tried to so, but i realized that it was converting the whole style not the text with the style.

 

var bul1 = doc.paragraphStyleGroups.itemByName( "Body Styles" ).paragraphStyleGroups.itemByName( "Lists" ).paragraphStyles.itemByName( "Bullet lvl 1" );
var bul2 = doc.paragraphStyleGroups.itemByName( "Body Styles" ).paragraphStyleGroups.itemByName( "Lists" ).paragraphStyles.itemByName( "Bullet lvl 2" );
var bul3 = doc.paragraphStyleGroups.itemByName( "Body Styles" ).paragraphStyleGroups.itemByName( "Lists" ).paragraphStyles.itemByName( "Bullet lvl 3" );
var num1 = doc.paragraphStyleGroups.itemByName( "Body Styles" ).paragraphStyleGroups.itemByName( "Lists" ).paragraphStyles.itemByName( "Num List lvl 1" );
var num2 = doc.paragraphStyleGroups.itemByName( "Body Styles" ).paragraphStyleGroups.itemByName( "Lists" ).paragraphStyles.itemByName( "Num List lvl 2" );
var num3 = doc.paragraphStyleGroups.itemByName( "Body Styles" ).paragraphStyleGroups.itemByName( "Lists" ).paragraphStyles.itemByName( "Num List lvl 3" );
 
// app.findTextPreferences.appliedParagraphStyle = bul1;
// bul1.convertBulletsAndNumberingToText();
// app.findTextPreferences.appliedParagraphStyle = bul2;
// bul2.convertBulletsAndNumberingToText();
// app.findTextPreferences.appliedParagraphStyle = bul3;
// bul3.convertBulletsAndNumberingToText();
// app.findTextPreferences.appliedParagraphStyle = num1;
// num1.convertBulletsAndNumberingToText();
// app.findTextPreferences.appliedParagraphStyle = num2;
// num2.convertBulletsAndNumberingToText();
// app.findTextPreferences.appliedParagraphStyle = num3;
// num3.convertBulletsAndNumberingToText();

// alert('Bullet lvl 1, 2, 3 and Number List lvl 1, 2, 3 converted to text.')
TOPICS
Scripting
2.6K
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

correct answers 1 Correct answer

Community Expert , Mar 28, 2023 Mar 28, 2023

Rather than using InDesign's Find to look for styles, you may be better off cycling through paragraphs and checking their style names. Something like this:

 

par = doc.stories.everyItem().paragraphs.everyItem().getElements();
re = /(Bullet|Num) lvl [123]/;
for (i = 0; i < par.length; i++) {
  if (re.test (par[i].appliedParagraphStyle.name)) {
    // do something
  }
}

 

Peter

Translate
Participant ,
Mar 27, 2023 Mar 27, 2023

all those bottom lines are shown as commented out, i just forgot to un-comment them before posting but when active they convert the entire style to text, removing the list formatting entirely, and 

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
LEGEND ,
Mar 27, 2023 Mar 27, 2023

You can go back and re-edit your original post - there is no time limit.

 

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 ,
Mar 28, 2023 Mar 28, 2023

I dont see any option to edit a post or comment, am i just completely missing it?

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 ,
Mar 28, 2023 Mar 28, 2023

Click '. . . More' and one of the options is 'Edit message'.

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 ,
Mar 28, 2023 Mar 28, 2023

I don't see that option on any of posts or comments. under my post i have: views, translate, report, follow, and reply. would be labeled as community beginner effect the options on posts i have?

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 ,
Mar 28, 2023 Mar 28, 2023

I've no idea.

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 ,
Mar 28, 2023 Mar 28, 2023

Hi @SweatersInSummer , I think you need to loop through the paragraphs and remove the overrides that are created when you change the paragraph styles—paragraph.clearOverrides()

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Paragraph.html#d1e501544__d1e508156

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 ,
Mar 28, 2023 Mar 28, 2023

Rather than using InDesign's Find to look for styles, you may be better off cycling through paragraphs and checking their style names. Something like this:

 

par = doc.stories.everyItem().paragraphs.everyItem().getElements();
re = /(Bullet|Num) lvl [123]/;
for (i = 0; i < par.length; i++) {
  if (re.test (par[i].appliedParagraphStyle.name)) {
    // do something
  }
}

 

Peter

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 ,
Mar 28, 2023 Mar 28, 2023

This was the answer i was circling around, thank you Peter. I was trying to loop through the paragraphs but had difficulty figuring out the correct syntax to access the .paragraphs, but the InDesign Object Model on indesignjs.de is kind of difficult to understand at times. for posterity my final code looks like:

var doc = app.activeDocument;

par = doc.stories.everyItem().paragraphs.everyItem().getElements();
re = /(Bullet|Num List) lvl [123]/;
for (i = 0; i < par.length; i++) {
  if (re.test (par[i].appliedParagraphStyle.name)) {
    par[i].convertBulletsAndNumberingToText();
  }
}

alert('Bullet lvl 1, 2, 3 and Number List lvl 1, 2, 3 converted to text.')
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
New Here ,
May 23, 2024 May 23, 2024

Thanks for your help, Peter. Is there any way to tell the script to look inside all the tables inside a document?

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 ,
May 23, 2024 May 23, 2024

Yes, there is. This version handles tables:

par = doc.stories.everyItem().
  tables.everyItem().
  cells.everyItem().
  paragraphs.everyItem().
  getElements();

re = /(Bullet|Num) lvl [123]/;
for (i = 0; i < par.length; i++) {
  if (re.test (par[i].appliedParagraphStyle.name)) {
    // do something
  }
}

It deals only with tables, so you would still need the previous version for the main text. (You need a separate version for footnotes as well).

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
New Here ,
May 23, 2024 May 23, 2024

Uauuuu.... superb, Peter. Thanks a lot!

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
New Here ,
Mar 13, 2025 Mar 13, 2025

Hi! i don't know what I did with this script back in the day...

I have tried to create it again with this code:

 

var doc = app.activeDocument;
par = doc.stories.everyItem().
tables.everyItem().
cells.everyItem().
paragraphs.everyItem().
getElements();

re = /(Bullet|Num) lvl [123]/;
for (i = 0; i < par.length; i++) {
if (re.test (par[i].appliedParagraphStyle.name)) {
par[i].convertBulletsAndNumberingToText();
}
}

 

But it doesn't work. What am I doing wrong? Thanks.

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
LEGEND ,
Mar 13, 2025 Mar 13, 2025

@Alberto Gutiérrez 

 

What error do you get?

 

Because it looks OK?

 

var doc = app.activeDocument;
par = doc.stories.everyItem().tables.everyItem().cells.everyItem().paragraphs.everyItem().getElements();

re = /(Bullet|Num) lvl [123]/;
for (i = 0; i < par.length; i++) 
{
  if (re.test (par[i].appliedParagraphStyle.name)) 
    {
      par[i].convertBulletsAndNumberingToText();
    }
}

 

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 ,
Mar 13, 2025 Mar 13, 2025

First thing is this script is looking for paragraph styles with the names of Bullet lvl 1, Bullet lvl 2, Bullet lvl 3, Num lvl 1, etc. can you confirm that the lists you are trying to convert are named like that as well?

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
LEGEND ,
Mar 13, 2025 Mar 13, 2025
quote

First thing is this script is looking for paragraph styles with the names of Bullet lvl 1, Bullet lvl 2, Bullet lvl 3, Num lvl 1, etc. can you confirm that the lists you are trying to convert are named like that as well?

By @SweatersInSummer

 

I don't think that would be the problem - if the name of the applied ParaStyle doesn't meet the criteria - script will just skip this paragraph.

 

And even if there are no Tables - script will just end instantly.

 

And it will/should skip empty Cells.

 

That's why I've asked @Alberto Gutiérrez if there are any error messages.

 

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 ,
Mar 13, 2025 Mar 13, 2025

I know, but considering the script is from my projects its looking for styles my team uses. If their files don't use those names for styles then the script will skip them and do nothing, and throw no error.

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
LEGEND ,
Mar 13, 2025 Mar 13, 2025

@SweatersInSummer

 

There will be no errors - just nothing will happen. 

 

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
New Here ,
Mar 13, 2025 Mar 13, 2025

Hi, thanks for your answers. Captura de Pantalla 2025-03-14 a las 7.50.44.png

(My InDesign is in spanish) The error says: "unknown object type"

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
LEGEND ,
Mar 14, 2025 Mar 14, 2025
LATEST
quote

Hi, thanks for your answers. Captura de Pantalla 2025-03-14 a las 7.50.44.png

(My InDesign is in spanish) The error says: "unknown object type"


By @Alberto Gutiérrez

 

But you don't have "main" function in your code? 

 

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