clear object style override in indesign using javascript

Participant ,
Mar 25, 2022 Mar 25, 2022

Copy link to clipboard

Copied

I am able to clear overrides of specific object style but i dont find anything related to object style override in Indesign extendscript object model! Is there anyway to clear overrides of object style using javascript?

I am trying to clear overrides in particular object style!

TOPICS
How to , Scripting

Views

145

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
community guidelines

correct answers 2 Correct answers

Adobe Community Professional , Mar 25, 2022 Mar 25, 2022
Hi Karthik SG, DOM documentation for clearObjectStyleOverrides() for pageItem: https://www.indesignjs.de/extendscriptAPI/indesign-latest/#PageItem.html#d1e208274__d1e210118 Or use applyObjectStyle() and use the second or the third argument: https://www.indesignjs.de/extendscriptAPI/indesign-latest/#PageItem.html#d1e208274__d1e209925 Regards, Uwe Laubender ( ACP )

Likes

Translate

Translate
Adobe Community Professional , Mar 25, 2022 Mar 25, 2022
Hi @Karthik SG, sorry I wasn't clear enough. As Uwe said, you need to target a page item, not the object style—that's why I said "myPageItem". To do what you want, you can find every page item with an object style applied using findObject, and then clear overrides on each found page item. See this script. - Mark overrideObjectStyleInDocument(app.activeDocument, 'Verankup'); function overrideObjectStyleInDocument(appOrDocument, objectStyleOrName, showResult) { // can accept app or document (...

Likes

Translate

Translate
Adobe Community Professional ,
Mar 25, 2022 Mar 25, 2022

Copy link to clipboard

Copied

I think it's just

myPageItem.clearObjectStyleOverrides();

 

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
community guidelines
Participant ,
Mar 25, 2022 Mar 25, 2022

Copy link to clipboard

Copied

Now I tried like this but not working for me,

objStyles = app.documents[0].objectStyles;
for(i=0; i<objStyles.length;i++){
    if(objStyles[i].name == "Verankup"){
   objStyles[i].clearObjectStyleOverrides();
   }
}

I got this Error: objStyles[i].clearObjectStyleOverrides is not a function

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
community guidelines
Adobe Community Professional ,
Mar 25, 2022 Mar 25, 2022

Copy link to clipboard

Copied

LATEST

Hi @Karthik SG, sorry I wasn't clear enough. As Uwe said, you need to target a page item, not the object style—that's why I said "myPageItem".

To do what you want, you can find every page item with an object style applied using findObject, and then clear overrides on each found page item. See this script.

- Mark

overrideObjectStyleInDocument(app.activeDocument, 'Verankup');

function overrideObjectStyleInDocument(appOrDocument, objectStyleOrName, showResult) {
    // can accept app or document (app will apply to all documents)
    if (
        appOrDocument.constructor.name != 'Document'
        && appOrDocument.constructor.name != 'Application'
    )
        return;

    app.findObjectPreferences = null;
    app.findObjectPreferences.appliedObjectStyles = objectStyleOrName;

    var found = appOrDocument.findObject(true),
        counter = 0;

    for (var i = 0; i < found.length; i++) {
        found[i].clearObjectStyleOverrides();
        counter++;
    }

    if (showResult !== false)
        alert('Overridden ' + counter + " items with object style.");
}

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
community guidelines
Adobe Community Professional ,
Mar 25, 2022 Mar 25, 2022

Copy link to clipboard

Copied

Hi Karthik SG,

DOM documentation for clearObjectStyleOverrides() for pageItem:

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#PageItem.html#d1e208274__d1e210118

 

Or use applyObjectStyle() and use the second or the third argument:

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#PageItem.html#d1e208274__d1e209925

 

Regards,
Uwe Laubender

( ACP )

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
community guidelines
Participant ,
Mar 25, 2022 Mar 25, 2022

Copy link to clipboard

Copied

Thanks @Laubender, i searched with keyterms clearOverride! I think thats why i missed to see this.

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
community guidelines
Adobe Community Professional ,
Mar 25, 2022 Mar 25, 2022

Copy link to clipboard

Copied

Karthik SG said:

" got this Error: objStyles[i].clearObjectStyleOverrides is not a function"

 

No wonder. Object styles do not have this method ( or function, a synonym for the word method in the DOM documentation ). Check the DOM documentation for objectStyle to see, that clearObjectStyleOverrides is not listed under category "Methods": https://www.indesignjs.de/extendscriptAPI/indesign-latest/#ObjectStyle.html

 

Visit the links that I posted earlier, scroll up, you'll see that both methods, clearObjectStyleOverrides() and applyObjectStyle() are listed in category "Methods" for the pageItem class.

 

On: When you or any user clears overrides with applied object styles in the GUI you do that on selected page items.

With a script you can do both, clear the overrides on selected items on the page; or you could do it with page items you address directly without any user selection in your document.

 

Do you want your script run on selected items, on a selection a user did?

 

Regards,
Uwe Laubender

( ACP )

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
community guidelines