Clear Overrides Throughout Document on Particular Object StyleObject

Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / Clear Overrides Throughout Document on Particular Object StyleObject

Viewing 25 reply threads
  • Author
    Posts
    • #94594
      Masood Ahmad
      Participant

      Hi,

      I was looking for a JavaScript that can remove the Overrides throughout the InDesign Document on a particular Object Style.

      Let’s say I have an Object Style named: “myDropShadow”, applied to multiple frames and images throughout the Document. Some of these elements have manual overrides done by a user. I would like to use the Script to remove any manual overrides for my shadow object style.

      While searching the net, I got this JavaScript from ID-Extras.com:

      Clear Overrides Throughout Document

      // Clear All Overrides
      // Written by TAW. (c) 2014 by Bookraft Solutions, Israel (Id-Extras.com)
      // Please do not delete this copyright notice.
      //
      var myOverrideType = OverrideType.ALL;
      // var myOverrideType = OverrideType.CHARACTER_ONLY;
      // var myOverrideType = OverrideType.PARAGRAPH_ONLY;
      var allStories = app.activeDocument.stories.everyItem();
      // Remove overrides from all stories
      try{
      allStories.clearOverrides(myOverrideType);
      }
      catch (e){alert ("No stories!")}
      // Remove overrides from all footnotes
      try{
      allStories.footnotes.everyItem().texts.everyItem().clearOverrides(myOverrideType);
      }
      catch (e){alert ("No footnotes!")}
      // Remove overrides from all table
      try{
      allStories.tables.everyItem().cells.everyItem().paragraphs.everyItem().clearOverrides(myOverrideType);
      }
      catch (e){alert ("No tables!")}
      alert("Overrides cleared!");

      This works but only on the Character/Paragraph Styles.

      There is a discussion here as well but that too covers the text styles:
      https://creativepro.com/remove-all-local-formatting-globally.php

      Can anyone help me tweak this script to work on a particular object style.

      Thanks in advance.

    • #94596
      Chad Beery
      Participant

      You can use Object Find/Change to do this by looking for the object style and replacing it with the same style.

    • #94600
      Masood Ahmad
      Participant

      Hi Chad, Thanks for reminding me of that. Is this somehow be scripted?

      • #94602
        Chad Beery
        Participant

        I’m guessing it could be but my script writing skills are limited.

    • #94605
      Masood Ahmad
      Participant

      No issues Chad,we are on the same boat.

      Can anyone provide me a one-liner script to achieve the goal.

    • #94607

      This cannot be done with one line.

      var oStyle = app.activeDocument.objectStyles.itemByName("b");
      app.findObjectPreferences = app.changeObjectPreferences = null;
      app.findObjectPreferences.appliedObjectStyles = oStyle;
      var fund = app.activeDocument.findObject();
      app.findObjectPreferences = app.changeObjectPreferences = null;
      
      for (var f = 0; f < fund.length; f++) {
        fund[f].applyObjectStyle(oStyle, true);
      }
      
    • #94628

      Hi Kai,

      Sure? =D

      var O = app.activeDocument.pageItems.everyItem().getElements(), S = app.activeDocument.objectStyles.item(“s”), P = O.length; while (P–) if (O[P].appliedObjectStyle == S) O[P].applyObjectStyle(S);

      One-single-line Script!

      (^/)

      Masood: I see you saw my comment about for free scripts! =D

    • #94629

      Shorter:

      var D = app.activeDocument, O = D.pageItems.everyItem().getElements(), S = D.objectStyles.item(“s”), P = O.length; while (P–) if (O[P].appliedObjectStyle == S) O[P].applyObjectStyle(S);

      (^/) =D

    • #94631

      Michel, a line is determinated at least by a “;” So your short line have 2 lines ;-)

      But: The goal in scripting is, to write readable scripts. If this is your style, putting everything in one line, avoid the use of parentheses, then this is no good practice.

      And: If you work with pageItems.everyItem(), you will not get every items!

      Kai

      • #94638

        Hi Kai,

        1/ It’s your personal interpretation of what is “a line”! No worry for me! ;-)
        2/ My code is totally readable! [about this point, I suggest you to take a look to the Great Master Marc Autret’s artwork!]. Especially, not sure adding or not parentheses everywhere would be more preferable! About this, Peter Kahrel wrote: “… many people […] write single lines in brackets […] but this is not needed …” relevant too about line returns!
        3/ I’m more interested by a technical discussion about your mention “… if you work with pageItems.everyItem(), you will not get every items! …”: your script won’t find: items on master pages or locked/not visible layers, locked items [and maybe other cases!], not mine!

        (^/)

        PS: Beyond writing its code, concentrate here such a script on 1 line was a joke! … but maybe you have less humour than me! ;-)

    • #94637
      Masood Ahmad
      Participant

      Hi Kai, Your code works well. I’ll check it further on the original files. Thanks a lot.

    • #102028

      I was looking for a script like this, but i have an additional question: The script works, but only if the object is visible. If it’s an anchored Image which is in overset text area (because it’s too big), the script can’t clear the overrides.

      Is it possible to find all items, whether they are “visible” or not?

      I need it for a big TOC where anchored images are used next to the text and they are way too big. If i apply an own object style to the images, the style is set, but the size doesn’t change. So the script should clear this to display the object with the correct size. Resizing all frames to make the images visible is not an option.

    • #102032

      Bruce, a short test shows, that the script works with image frames in overset too. So you have maybe another problem? How do you set the size of your object? Which version of InDesign?

      Kai

    • #102041

      I have a text frame with anchored images set to object style “format1”, which sets the object size of the images to 87x87mm. The TOC has a layout with several text frames with 30x30mm for the images. The images there have to be “format2” which sets a size of 30x30mm for the anchored images.

      If i load the TOC, the images are there, but not visible (too big) because of “format1”. I use find/change to set the object style to “format2”. “format2” is set, but the size is still 87x87mm. If i use the script, nothing happens, the override is still there. But if i resize the text frame to make the image visible, the script then works.

      It’s the same thing like changing the object style per find/change. If the image is visible, everything works. If not, the format is set correctly, but with override. Or is this a bug?

    • #102042

      Hm, I’m working here with CC2015, but I could try my new MacBook where CC2018 is installed ;-) I’m not sure, if this is logic, that you can set a size of something only, when it is visible …

      Can you built a litle example? 2-3 pages, one or two big pictures in text with format1 and your generated toc …? Sent me your file with your dummy pics to [email protected]

      btw.: Do you know, that you can refresh the toc with a script too and could temporarily increase the frame (as Plan B, if Plan A doesn’t work)

      Kai

    • #105099

      Im having this issue with tables. I use linked xlxs files with the sheets linked to text frames with tables inside. When i update the link file it some sets the paragraph style to a different one. It seems like some bug. Prior use the select the correct one before doing the update and than it worked. But know it simple switches to a different one.

      I can use Clear All Overrides script, but that destroy my table row styles ive added.

      Does someone know a trick to solve this?

    • #105100

      Rombout, I do not understand the problem. Maybe a example before/after would help.

    • #105103

      Okay here goes.

      Ive made a catalogue wich uses excel sheets with set set range values for header info and spec info. All is set with style as for the tables and rows. The problem which is happening is that on each save all links need to be updated.

      Somehow since yesterday when i do update all my frame which contain the a table with a certain paragraph style get a new paragraph style. Ive even added object frame styles to try to suppress this and this was working prior.

      I get the feeling that when you have nothing selected and go the the paragraph styles in the top menu and pick something it somehow applies this. Prior i used the preselect the proper paragraph style in the styles list and this worked. But now it keeps jumpig to a different one.

      Before i update links
      https://www.dropbox.com/s/024vl8fu55gt48e/Before.png?raw=1

      The warning that i loose local edits. Not sure what is wrong with this, because sometimes it doesnt give that warning yet other times it gives it for each and every linked file. There doesnt seem to be standard, even when i havent done any edits i still get this.
      https://www.dropbox.com/s/0klz0t1gairtsqj/warning.png?raw=1

      After i update, see the header called “Banner 510”, in the op right you can see the frame some how gets a different paragraph style. While all is set to paragraph style in the table style options and also in the object frame options.
      https://www.dropbox.com/s/muhql84y39pjyjt/after.png?raw=1

    • #105104

      I notice when i select it and then update it, it gets a different paragraph style. Yet when i dont select it, than it works properly. This is bugging me a lot, it looks like some bug to me.No where is that style it gets set to that frame.

      Than once i did the update without selecting any table in a frame. Than it does update all other without issues or assigning a new paragraph style to the frame. Its really weird.

    • #105106

      Good to read, that you find a solution. If you work with table styles, cell styles within a table style, para styles within cell styles and have no overrides on cell styles and table styles, this shouldn’t be a problem.

    • #105107

      The table doesn’t get changed its the text where the table is placed in. Yet I’ve even added aobject from to these. Also the issue doesn’t happen consistently. When I noticed that selecting nothing didn’t do anything. I then reverted the docdocument and tried again with selecting the frame and than updating it this time it also worked perfect. I than restarted InDesign and redid both steps. This time both if of them worked properly.

      But the issue has happened before today. Luckily I’ve applied styles to everything I can think off, so using a clear over override scripts fixes it quickly but still I wonder why certain times it works and other times it doesnt

    • #117185
      Year 1917
      Member

      i seem to get a error when using any of the above scripts (cc2019)
      can someone tell me how to use them, or it simply does not work in this version?

      thanks

    • #117342

      What kind of errror?

    • #12243973

      Hi Kai

      When I try to use your script, I’m keep getting this error https://bit.ly/2V6Bd1k. Can you help me to solve this problem?

    • #12243974
      Brian Pifer
      Participant

      Make sure whatever is inside quotation marks (“b”) on the following line is an actual named Object Style in your document:

      var oStyle = app.activeDocument.objectStyles.itemByName(“b”);

      An example of the change would be:

      var oStyle = app.activeDocument.objectStyles.itemByName(“myNamedStyle”);

    • #12432991

      Perhaps if I got time this weekend I can alter the script and make the user ask for style to select from a drop-down. That way you won’t need to alter the script each time. Would be way more convenient wouldn’t it?

    • #12304369

      Sorry almost forgot about it. Is this perhaps more handy?
      Ive altered it a bit and now you get a dialog window and you can pick the object style from the dropdownlist. It will then go over all items and clear the overrides.

      I got another idea by making it more functional by letting the user choose between object-, character- or paragraph-style. That way we got 3 different versions of a script in one :)

      https://ibb.co/42wQn0h

      Would be nice if this forum had a bit more advanced messaging system and also allowed for image uplaod

    • #12343070

      Tried your “oneliner” but get error because of the comma’s. Thought it could be possible

Viewing 25 reply threads
  • You must be logged in to reply to this topic.
>
Notice: We use cookies on our websites to give you a great online experience. If you keep browsing, we'll assume you're ok with this. For more information, see our privacy policy. By closing this banner, you agree to the use of cookies.I AGREENo