Highlighted

How to Remvoe Unused Table Styles

Engaged ,
Aug 21, 2020

Copy link to clipboard

Copied

Hi Pros,,

Again i tried to remove the table styles depending on the previous technique but nothing happened even no error message?!, Please Help me making code works and thanks in Advance :

 

//Remove Unused Table Styles
removeUnusedTableStyles();

function removeUnusedTableStyles() {
	var TableStyles, found,
	documentStories = app.activeDocument.stories.everyItem();
    TableStyles = documentStories.tables.everyItem().getElements();
	for (var i = TableStyles.length - 1; i >= 1; i--) { // skip default style: [None]
            app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;
            app.findTextPreferences.table.appliedTableStyle.name = TableStyles[i];
            found = TableStyles.table.appliedTableStyle.name();
			if (found.length == 0) {
				TableStyles[i].remove();
		}		
	}
    app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;
}   

 

 Best

medos20

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

Hi Medos,

I don't see the table property existing in findTextPreferences object, so this code would crash. I don't see the same in grep search preference as well, so this idea might not work for table styles.

What I can think of is the old school way of iterating over all the tables in the document, make a list of used styles and then delete the styles that do not exist in this list

-Manan

Topics

Scripting

Views

50

Likes

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

How to Remvoe Unused Table Styles

Engaged ,
Aug 21, 2020

Copy link to clipboard

Copied

Hi Pros,,

Again i tried to remove the table styles depending on the previous technique but nothing happened even no error message?!, Please Help me making code works and thanks in Advance :

 

//Remove Unused Table Styles
removeUnusedTableStyles();

function removeUnusedTableStyles() {
	var TableStyles, found,
	documentStories = app.activeDocument.stories.everyItem();
    TableStyles = documentStories.tables.everyItem().getElements();
	for (var i = TableStyles.length - 1; i >= 1; i--) { // skip default style: [None]
            app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;
            app.findTextPreferences.table.appliedTableStyle.name = TableStyles[i];
            found = TableStyles.table.appliedTableStyle.name();
			if (found.length == 0) {
				TableStyles[i].remove();
		}		
	}
    app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;
}   

 

 Best

medos20

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

Hi Medos,

I don't see the table property existing in findTextPreferences object, so this code would crash. I don't see the same in grep search preference as well, so this idea might not work for table styles.

What I can think of is the old school way of iterating over all the tables in the document, make a list of used styles and then delete the styles that do not exist in this list

-Manan

Topics

Scripting

Views

51

Likes

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
Aug 21, 2020 0
Adobe Community Professional ,
Aug 21, 2020

Copy link to clipboard

Copied

Hi Medos,

I don't see the table property existing in findTextPreferences object, so this code would crash. I don't see the same in grep search preference as well, so this idea might not work for table styles.

What I can think of is the old school way of iterating over all the tables in the document, make a list of used styles and then delete the styles that do not exist in this list

-Manan

Likes

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
Reply
Loading...
Aug 21, 2020 1
medos20 LATEST
Engaged ,
Aug 21, 2020

Copy link to clipboard

Copied

Thank you, Can you show me Example? at least small one, Thanks in Advance

Best

medos20

Likes

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
Reply
Loading...
Aug 21, 2020 0