Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

How to remove all unused paragraph styles of an InDesign Document through Javascript?

Return to Member Forum

  • Author
    Posts
    • #62164
      Bala S
      Participant

      I want to remove all unused items from my InDesign Document through Javascript. To do this I am enabling menuActions. But I could not run all menus. For example, I can enable/run the “Delete Unused Layers” menu through following javascript coding

      app.menuActions.item(“Delete Unused Layers”).invoke();

      But I could not enable/run the “Select All Unused” from style palette. Please advise is this possible through Javascript?. If possible please help me on this. Because I want to delete all unused styles from my Document.

    • #62165

      Attempting to invoke “Select All Unused” probably doesn't work because there are several menu actions with that title. So I dug down into the menu structure: menu “Paragraph Style Panel Menu”, menu item “Select All Unused”, then down to the action this item performs:

      app.menus.item(“Paragraph Style Panel Menu”).menuItems.item(“Select All Unused”).associatedMenuAction.invoke();

      This will select 'unused paragraph styles', just as it does in the user interface; and, just like in the user interface, it does nothing more. To delete them, add this line:

      app.menus.item(“Paragraph Style Panel Menu”).menuItems.item(“Delete Styles…”).associatedMenuAction.invoke();

      (But note that this might fail if [Basic Paragraph] is among the unused styles; again, just like in the interface itself.)

    • #62178
      Bala S
      Participant

      Dear Jongware,

      First of all Thanks for you reply.

      I had checked your coding in Adobe InDesign CS4. First one is (“Select All Unused”) working fine. But although [Basic Paragraph] is not selected, “Delete Styles…” is not working. Please advise is there any other way to perform that action?

      Note: I am getting the error: “Object is invalid”

    • #62179

      Gosh, I got it wrong then? (After retrying) … no I did not. Almost not, that is.

      First of all, if you copied my line from the post, make sure the three dots are actually three dots. The forum software translated them in an ellipsis. With that out of the way, let's experiment.

      Does it work? No. Why not? There are no “unused styles” in my test document.

      Next try, with an added style. Does it work? No. Why not? The first line on its own does select this one style, but the “Delete styles…” command fails. Why? When there is only one style selected, the menu actually reads “Delete Style…” — singular. Changing the 2nd line to this exact text makes it — finally — work as expected; and so does adding one more unused style and using the original lines.

      Can you “count” how many styles are selected after the first line? No. Only thing left is to wrap this line into a try … catch statement, and if one fails, try the other (and that may fail as well, if there are no unused styles or — insiduously — your Basic Paragraph Syles is “unused”). So the, uh, (I was going to say “best”!) least worse solution could be something like

      1. make sure Basic Paragraph is used. Create a text frame and apply this style; delete it when done.

      2. add not one but two new paragraph styles. Make sure one is not “based on” the other, because that will count as “being used”.

      3. invoke “select unused”

      4. invoke “delete styles …” — using the plural ought to be safe.

      Lesson learned: better not try to use “menu invoke”! A quick google lead me to this thread-from-the-past, but the general idea ought still work for CS4, 5, 6 and beyond: https://forums.adobe.com/thread/500399

    • #62183
      Bala S
      Participant

      Dear Jongware,

      Sorry for my mistake and Thank you very much for your help. Now it is working fine.

Viewing 4 reply threads
  • You must be logged in to reply to this topic.
Forum Ads