15 Replies Latest reply on Jan 28, 2015 3:43 PM by ThinkingThings

    How to Open/Display an Object Styles Style Name Menu

    ThinkingThings Level 1

      Greetings, Friends...

      I am at loss as to how to open (in scripting of course) a specific object style subitem from the Object Styles Panel.

      I can open (in VB.NET) the Object Styles Panel with

           app.Panels("Object Styles").Visible = True     

      but would like to be able to open the sub item in just one command instead of two.

      Any ideas?  Thanks in advance!!

        • 1. Re: How to Open/Display an Object Styles Style Name Menu
          Laubender Adobe Community Professional & MVP

          @ThinkingThings – I can only answer in context of ExtendScript…

           

          1. To invoke a specific menu action you need to activate it.

          2. A specific menu action of a panel is activated, if you open the panel.

          So you cannot open the "sub item" without one single command.

           

          3. Using panel names depends highly of the locale of the InDesign app.

          4. There are locale-independent names available for most of the menus.

           

          In your case and written in ExtendScript that would be:

           

          app.panels.itemByName("$ID/ObjStylesTreeViewPanelName").visible = true;
          
          

           

          How did I get the right name?
          I used "Objektformate", the name of the "Object Styles Panel" in my German InDesign and did:

           

          app.findKeyStrings("Objektformate");
          //Result was an Array of key strings:
          //ID/kObjectStyles,$ID/kSyncObjectStyleName,$ID/ObjStylesTreeViewPanelName
          
          

           

          "$ID/ObjStylesTreeViewPanelName"

           

          of course looked most promising. Here some documentation on that method:

          Adobe InDesign CS6 (8.0) Object Model JS: Application

           

          So let's dig deeper here…

          Say, you want to select all unused object styles, you have to:

          1. Open the panel

          2. Invoke the right menu action

           

          Finding the right menu action by its name is possible with app.findKeyStrings(). "$ID/SelectUnusedObjectStyles" looked most promising.

          But unfortunately the locale independent name of that action is used several times scattered over the interface of InDesign.

           

          So the following did not work:

           

          app.panels.itemByName("$ID/ObjStylesTreeViewPanelName").visible = true;
          app.menuActions.itemByName("$ID/SelectUnusedObjectStyles").invoke();
          
          

          Error: Action is not activated!

           

          What next? Ah! Every menu action has an unique ID. But be prepared, that this ID might vary from InDesign version to version or install to install. But we have a chance to get the right ID to work by using the locale independent name of the right menu action:

           

          app.panels.itemByName("$ID/ObjStylesTreeViewPanelName").visible = true;
          var myIDs = app.menuActions.itemByName("$ID/SelectUnusedObjectStyles").id;
          //Result with InDesign CS5.5 is an Array with 8 ID numbers:
          //8454,8474,16395,68111,113167,132111,132131,133143
          
          

           

          8 numbers to chose from. Which one is the right one?

          Let's go on:

           

          if(myIDs.constructor.name === "Array"){
          
          for(var n=0;n<myIDs.length;n++){
              try{
                  app.menuActions.itemByID(myIDs[n]).invoke();
                  $.writeln(myIDs[n]+"\t"+"invoked");
                  }catch(e){$.writeln(myIDs[n]+"\t"+e.message)};
              };
          
          };
          
          

           

          Of course you could break the loop, if the right ID is found…

          If you are using a different version of InDesign your IDs may vary.

           

          Uwe

          • 2. Re: Re: How to Open/Display an Object Styles Style Name Menu
            Laubender Adobe Community Professional & MVP

            Hm, just another thing on app.findKeyStrings() and the returned array of locale-independent strings and their IDs:

             

            Let's say I want to use "Select All Unused" in the Object Styles Panel with my German InDesign version, I would do app.findKeyStrings("Alle nicht verwendeten auswählen"), like described in the post above, to find the right key string.

             

            But it seems too much effort to select one of the returned strings.

            To my surprise, ALL returned key strings have one thing in common:

            The same Array of IDs.

             

            //String "Select All Unused" with app.findKeyStrings():
            //In my German InDesign version that string is: "Alle nicht verwendeten auswählen"
            
            var myKeyStrings = app.findKeyStrings("Alle nicht verwendeten auswählen");
            
            //RESULT: Array of 6 different strings:
            //$ID/Select All Unused,$ID/Select All Unused_2,$ID/kSelectAllUnused,$ID/SelectUnusedObjectStyles,$ID/#CondTextUI_SelectUnusedMenu,$ID/SelectAllUnused
            
            //Let's loop through this array and find out their IDs or their ID-Arrays:
            
            for(var n=0;n<myKeyStrings.length;n++){
                $.writeln(myKeyStrings[n]+"\t"+app.menuActions.itemByName(myKeyStrings[n]).id);
                };
            
            //Interesting results. All found key strings return the same array of IDs:
            /*
            $ID/Select All Unused    8454,8474,16395,68111,113167,132111,132131,133143
            $ID/Select All Unused_2    8454,8474,16395,68111,113167,132111,132131,133143
            $ID/kSelectAllUnused    8454,8474,16395,68111,113167,132111,132131,133143
            $ID/SelectUnusedObjectStyles    8454,8474,16395,68111,113167,132111,132131,133143
            $ID/#CondTextUI_SelectUnusedMenu    8454,8474,16395,68111,113167,132111,132131,133143
            $ID/SelectAllUnused    8454,8474,16395,68111,113167,132111,132131,133143
            */
            

             

            So we have a chance to invoke the right menu action without exactly knowing the right key string or the right ID number. Just use one of the listed ones and loop through their IDs Array with app.menuActions.itemByID(Number).invoke() after making the panel visible.

             

            Or am I missing something here?

             

            Uwe

            • 3. Re: Re: Re: How to Open/Display an Object Styles Style Name Menu
              ThinkingThings Level 1

              Hi Uwe,

               

              First let me say THANK YOU for the time that you have spent so far in illustrating potential fixes for my dilemma. I figure that you are either a great teacher or that you write books on these subjects. You did a FANTASTIC job in illustrating everything… Again, THANK YOU!

               

              I believe that one of the key findings in your study that made things "happen" for me was the revelation that the panel needed to be open in order for an active item in the item list below to be selected. Prior to my post, I had tried the menuActions.itemByID(113286) by itself, and actually it DOES select the active item that I want (still with the panel closed), but it doesn't slide open the object styles panel, so I figured that nothing was happening and/or that it didn't work.

               

              I may not have explained myself properly… The item that I want to select is an existing object style (in this case "panel"). This can be accessed through the context menu once the desired object style is activated. The context menu option would be 'Edit "Panel"…' which is the first selection on the context menu. I think that your second post mentioned that I possible wanted

               

              Interestingly enough, while searching through all of the app.MenuActions() results I came upon the following:

               

              8483: Edit "^1"...(Panel Menus:Paragraph Styles)

              8484: Duplicate Style...(Panel Menus:Paragraph Styles)

              8485: Delete Style...(Panel Menus:Paragraph Styles)

              8486: Redefine Style(Panel Menus:Paragraph Styles)

               

              Please note that the numbers are the MenuAction Ids. These 4 items just happen to match the active object style's first 4 context menu items and I thought that the '^1' could serve as a placeholder for the underlying active item. But NOWHERE could I locate anything like this for 'Object Styles'. I tried the 8483 MenuAction, but it didn't work.

               

              In Javascript, here's what I have so far:

               

              app.panels.itemByName("$ID/ObjStylesTreeViewPanelName").visible = true;    //opens panel menu

              app.menuActions.itemByID(113286).invoke();          // takes to panel item (my name for my object style)

               

              At this point, I'm showing the correct active Object Style ('Panel in my case). If possible, from this point I need to: 

                1. open the context menu for the active Object Style
                2. Activate 'Edit "Panel"...' on the context menu.


              Do you think that this is possible? Please let me know if you need any more information.

               

              Thank you for your kind assistance!

               

              TT

              • 4. Re: Re: Re: Re: How to Open/Display an Object Styles Style Name Menu
                Laubender Adobe Community Professional & MVP

                @TT – I think, that in the moment you are opening the Object Styles Panel, it will be unsure, if any of the object styles are in an active state. It will depend on the selection of page items you made or how you left the panel the last time you selected an object style within (but I'm not sure about the exact behavior).

                 

                However, If a distinct object style is selected, I think you could invoke the "Style Options..." submenu of the panel (that is not the context menu of the selected object style).

                 

                In my German version this is the sub menu "Formatoptionen…":

                 

                app.findKeyStrings("Formatoptionen...");
                //$ID/Style Options...,$ID/ObjectStyleOptions
                

                 

                Note: The three dots behind the name are individual dots, not one "ellipses".

                 

                So far so good…

                But even if you can find the right ID number for invoking this option it would not work for scripting.

                 

                In my case, InDesign CS5.5 German on OSX 10.6.8, the ID 113159 was the right one.

                But trying to invoke the menu was doing the following:

                1. It does open the dialog (Yes!), but it:

                2. Immediately closing the dialog (Arrgh!)

                3. Throwing the following error (ARRRRGH!):

                 

                "Mit der angeforderten Aktion wurde ein asynchrones, modales Dialogfeld geöffnet, für das eine Vorschau erstellt werden kann. Dies ist nicht mit der Skriptarchitektur kompatibel, daher wurde das Dialogfeld mit der Standardschaltfläche automatisch verworfen."

                 

                Roughly translated:

                "The action you provided has opened a asynchronous, modal dialog field, that is able to provide a "Preview" view. This is not compatible with the scripting architecture. Because of that that dialog field with that standard button was closed automatically."

                 

                So it seems that you cannot do what you want, because the "Preview" functionality is integrated in that dialog.

                 

                Btw. I think, we already had that discussion somewhere in this Scripting Forum…

                 

                Uwe

                • 5. Re: How to Open/Display an Object Styles Style Name Menu
                  Laubender Adobe Community Professional & MVP

                  A more general note on working with menu actions:
                  Be prepared getting stuck, be prepared even for crashing InDesign.

                   

                  One example:
                  If you try to remove all unused object styles with the appropriate menu action, InDesign will (could) crash immediately, if there are NO unused object styles. However, it will work as expected, if there are one or some unused object styles in the Object Styles Panel (tested with InDesign CS5.5 – I should investigate this problem a bit more, but I will not; see my comment immediately below).

                   

                  Then it's better to walk through all page items of the document and list all used object styles, single out the unused ones and remove that with the remove() method.

                   

                  In your case:
                  What is your goal?

                  1. Change some properties of a distinct object style?

                  Do it directly with the ObjectStyles class of objects.

                   

                  2. Present the user the UI dialog?
                  Then, I think, there is no chance doing this with ExtendScript.

                  Or rebuild the whole dialog with ScriptUI (of course I'm kidding here)…

                   

                  Uwe

                  • 6. Re: How to Open/Display an Object Styles Style Name Menu
                    Laubender Adobe Community Professional & MVP

                    Now I found the older thread I mentioned:

                     

                    kapoor_aman27 Sep 12, 2014 2:10 PM

                    I want to open "Paragraph Style Options" dialogue using Script(jsx)

                     

                    Re: I want to open "Paragraph Style Options" dialogue using Script(jsx)

                     

                    Maybe it will work for you when on a newer version of InDesign and on Windows OS. ?!

                    Please, let me know.

                     

                    Uwe

                    • 7. Re: Re: Re: Re: How to Open/Display an Object Styles Style Name Menu
                      ThinkingThings Level 1

                      Hi Uwe,

                      I just wanted to update you that, in fact, I AM able to get exactly what I want with presenting an "opened" UI to the user. Your help has been invaluable. I am working on modularizing it and when finished will post my findings. I am working with ID CC 2014 on Windows, not sure whether that matters. I will keep you posted.

                      Thanks -- TT

                      • 8. Re: Re: Re: Re: How to Open/Display an Object Styles Style Name Menu
                        ThinkingThings Level 1

                        Hi Uwe,

                        Just a further update... it is interesting that my own search of Key Strings and related Actions (written in .NET, of course ;-) ) result in the use of the exact same IDs of the "standard" menu items that you had (see below). I am running ID CC2014 on Windows and I believe that you are CS5.5 on a Mac. A few versions of separations and different OS platforms. Interesting...  But I don't believe that you can just use any of the Id's of the set that is resultant from an MenuAction.ItemByName() search, as there appears to "Areas" (see MenuItem.Area property) that play into the usefulness of these MenuItem Ids. I have managed to "automate" the selection of the proper "area" that I want but it dowsn;t seem to be working in 100% of the scenarios. So I will get back to you...

                         

                        Here's my results:

                         

                        === KeyStrings searched by 'Select All Unused' ===

                        $ID/SelectUnusedObjectStyles

                        $ID/Select All Unused

                        $ID/#CondTextUI_SelectUnusedMenu

                        $ID/SelectAllUnused

                        $ID/Select All Unused_2

                        $ID/kSelectAllUnused

                        Matches found: 6

                        ------------------------------------------------------------------------------------------ ----------

                        === MenuActions searched by '$ID/SelectUnusedObjectStyles' ===

                        8454: Select All Unused(Panel Menus:Character Styles, Label: )

                        8474: Select All Unused(Panel Menus:Paragraph Styles, Label: )

                        16395: Select All Unused(Panel Menus:Swatches, Label: )

                        68111: Select All Unused(Panel Menus:Trap Presets, Label: )

                        113167: Select All Unused(Panel Menus:Object Styles, Label: )

                        132111: Select All Unused(Other, Label: )

                        132131: Select All Unused(Panel Menus:Cell Styles, Label: )

                        133143: Select All Unused(Panel Menus:Conditional Text, Label: )

                        Matches found: 8

                        ------------------------------------------------------------------------------------------ ----------

                        === MenuActions searched by '$ID/Select All Unused' ===

                        8454: Select All Unused(Panel Menus:Character Styles, Label: )

                        8474: Select All Unused(Panel Menus:Paragraph Styles, Label: )

                        16395: Select All Unused(Panel Menus:Swatches, Label: )

                        68111: Select All Unused(Panel Menus:Trap Presets, Label: )

                        113167: Select All Unused(Panel Menus:Object Styles, Label: )

                        132111: Select All Unused(Other, Label: )

                        132131: Select All Unused(Panel Menus:Cell Styles, Label: )

                        133143: Select All Unused(Panel Menus:Conditional Text, Label: )

                        Matches found: 8

                        ------------------------------------------------------------------------------------------ ----------

                        === MenuActions searched by '$ID/#CondTextUI_SelectUnusedMenu' ===

                        8454: Select All Unused(Panel Menus:Character Styles, Label: )

                        8474: Select All Unused(Panel Menus:Paragraph Styles, Label: )

                        16395: Select All Unused(Panel Menus:Swatches, Label: )

                        68111: Select All Unused(Panel Menus:Trap Presets, Label: )

                        113167: Select All Unused(Panel Menus:Object Styles, Label: )

                        132111: Select All Unused(Other, Label: )

                        132131: Select All Unused(Panel Menus:Cell Styles, Label: )

                        133143: Select All Unused(Panel Menus:Conditional Text, Label: )

                        Matches found: 8

                        ------------------------------------------------------------------------------------------ ----------

                        === MenuActions searched by '$ID/SelectAllUnused' ===

                        8454: Select All Unused(Panel Menus:Character Styles, Label: )

                        8474: Select All Unused(Panel Menus:Paragraph Styles, Label: )

                        16395: Select All Unused(Panel Menus:Swatches, Label: )

                        68111: Select All Unused(Panel Menus:Trap Presets, Label: )

                        113167: Select All Unused(Panel Menus:Object Styles, Label: )

                        132111: Select All Unused(Other, Label: )

                        132131: Select All Unused(Panel Menus:Cell Styles, Label: )

                        133143: Select All Unused(Panel Menus:Conditional Text, Label: )

                        Matches found: 8

                        ------------------------------------------------------------------------------------------ ----------

                        === MenuActions searched by '$ID/Select All Unused_2' ===

                        8454: Select All Unused(Panel Menus:Character Styles, Label: )

                        8474: Select All Unused(Panel Menus:Paragraph Styles, Label: )

                        16395: Select All Unused(Panel Menus:Swatches, Label: )

                        68111: Select All Unused(Panel Menus:Trap Presets, Label: )

                        113167: Select All Unused(Panel Menus:Object Styles, Label: )

                        132111: Select All Unused(Other, Label: )

                        132131: Select All Unused(Panel Menus:Cell Styles, Label: )

                        133143: Select All Unused(Panel Menus:Conditional Text, Label: )

                        Matches found: 8

                        ------------------------------------------------------------------------------------------ ----------

                        === MenuActions searched by '$ID/kSelectAllUnused' ===

                        8454: Select All Unused(Panel Menus:Character Styles, Label: )

                        8474: Select All Unused(Panel Menus:Paragraph Styles, Label: )

                        16395: Select All Unused(Panel Menus:Swatches, Label: )

                        68111: Select All Unused(Panel Menus:Trap Presets, Label: )

                        113167: Select All Unused(Panel Menus:Object Styles, Label: )

                        132111: Select All Unused(Other, Label: )

                        132131: Select All Unused(Panel Menus:Cell Styles, Label: )

                        133143: Select All Unused(Panel Menus:Conditional Text, Label: )

                        Matches found: 8

                        ------------------------------------------------------------------------------------------ ----------

                        • 9. Re: Re: Re: Re: Re: How to Open/Display an Object Styles Style Name Menu
                          ThinkingThings Level 1

                          Hi Uwe,

                           

                          I'm not sure where to start -- or finish, for that matter.  Here's the VB.NET code that works (hardcoded IDs):

                           

                                  app.Panels("$ID/ObjStylesTreeViewPanelName").Visible = True    'Opens Object Styles Panel
                                  app.MenuActions.ItemByID(113286).Invoke()                      'Moves Active Panel Item to "Panel"
                                  Threading.Thread.Sleep(500)                                    'sleep 500ms to let system move to active panel
                                  app.MenuActions.ItemByID(113159).Invoke()                      'Opens Style Options...
                          

                           

                          It's VB.NET, but it's pretty clear, I think. Now for my test document, I can modularize the code to not have direct ID number, but rather code to loop through the MenuActions, further clarify them by utilizing the "Area" property and presto, everything works as planned: the user is presented with an opened UI to the exact Object Style that we want it opened to. I should have taken a video, it was SO pretty! :-)  I can present the code if you still need more info.

                           

                          But here's the problem(s).

                          1. If I move an Object Style in the list, it's a game changer and the wrong style is opened.
                          2. It seems that somehow a cached copy of MenuAction indexes are kept, as documents that are no longer open in ID still show their Object Styles in a listing of MenuActions by Index number. I've tried closing and reopening both ID and my .NET application, but the indexes still remain.
                          3. If I open a different document that has a "Panel" Object Style, unless it is in the same position as the original test document, as if the MenuAction search for "Panel" doesn't mean anything. I can get everything to work perfectly, but I just can't seem to move the needle on activating the appropriate Object Style in order to then invoke the Open Style Options menu (thanks for that one though, Uwe -- it was a lifesaver!).

                           

                          There's some piece that I am missing, and it's driving me nuts. The end doesn't justify the means in this situation, no doubt -- but it really has me perplexed. I don't know enough about he ID menu structure. I find it hard to believe that there isn't a quicker way to open up a Popup UI Dialog in code for a given Style (Object, Paragraph, Character, etc...).

                           

                          So I don't know where to go now with this. I hate to sound defeated as it's usually not my style. I believe that this is doable, it's just that I'm missing one small piece that, if I could get it, the logic should probably work for most/all style classes with a few parameters called to a function.

                           

                          If you have any ideas that can lend direction, it would be most appreciated. You've spent an inordinate amount of time on this already and I really do appreciate it. I hate to surrender on this but it may have to go that way. Your thoughts are most welcome.

                           

                          Best regards,

                          TT

                          • 10. Re: Re: Re: Re: Re: How to Open/Display an Object Styles Style Name Menu
                            Laubender Adobe Community Professional & MVP

                            @TT – hm, yes. The problems…

                             

                            Your problem #1 was discussed (implicitly) in this other thread I mentioned.

                            You cannot be sure what object style is selected in the panel.

                             

                            Unless:

                            A. You select a page object with that style (not a good user experience)

                            B. You add a new object to the active spread, apply the style and select that (also not that a good user experience, but better than A, because you can avoid jumping to a different spread)

                             

                            Your problem #2 is very interesting, but I think I cannot help here.

                             

                            For problem #3 I think "solution" #1 will apply.

                             

                            Getting everything under control could mean rebuilding the Opject Styles Panel with ScriptUI.
                            Or building a plugIn with C++ (but that's not my realm).

                             

                            Uwe

                            • 11. Re: Re: Re: Re: Re: How to Open/Display an Object Styles Style Name Menu
                              ThinkingThings Level 1

                              >>  A. You select a page object with that style (not a good user experience)

                              Uwe -- actually you may have solved the problem right there. I'll get on it tomorrow...  Thanks!!    -TT

                              • 12. Re: How to Open/Display an Object Styles Style Name Menu
                                Laubender Adobe Community Professional & MVP

                                @TT – looking at your code, it's interesting that you are using a sleep period of half a second before doing the next step, invoking the menu action for showing the Object Style Options.

                                 

                                Can you comment on that?

                                 

                                Uwe

                                • 13. Re: How to Open/Display an Object Styles Style Name Menu
                                  ThinkingThings Level 1

                                  Sure, Uwe!    The  UI lags a little and, since in the next line I am opening the Style Options of the “presently selected style”, without the sleep code the code (on the script side) was moving on and sometimes choosing the style options of the wrong style. Remember, that the script in this case is running as a separate executable through COM. Hope this helps!   I will get back to you shortly regarding your last comment/suggestion as to how to best approach this.  Thanks!  -TT

                                  • 14. Re: Re: How to Open/Display an Object Styles Style Name Menu
                                    ThinkingThings Level 1

                                    Okay -- here's the final answer. It contains just a small "hack", in that there appears to be no method that allows for the selection of a particular style within the style panel. So we create a temp object, apply the target style to it, which activates the target style within the panel, make the desired changes to the style in the panel dialog and then delete the temp object. Many thanks to Laubender (Uwe) for the information and suggestions that led to this being able to work.  -TT

                                     

                                    Here's the code (in VB.NET but the process should be readily apparent):

                                     

                                            Dim app As New InDesign.Application
                                            Dim aDoc As ID.Document = app.ActiveDocument
                                            'style panel names -- should be self explanatory
                                            '$ID/ObjStylesTreeViewPanelName
                                            '$ID/ObjStylesParaStylePanelName
                                            '$ID/Character Styles
                                            '$ID/Table Styles
                                            '$ID/Cell Styles
                                            Dim curSelections = aDoc.Selection                              'to remember current selections (if any)
                                            app.Panels("$ID/ObjStylesTreeViewPanelName").Visible = True     'open desired styles panel (see above for options)
                                            aDoc.Selection = ID.idNothingEnum.idNothing                     'don't want to apply style to unintended objects
                                            Dim tmpRect = aDoc.Rectangles.Add() : With tmpRect              'creates temp object (may need to modify for other style types)
                                                .AppliedObjectStyle = aDoc.ObjectStyles("Panel")            'insert your intended style name to change
                                                .Name = "_deleteThis"                                       'in case something goes wrong the object will be easy to find :-)
                                            End With
                                            aDoc.Select(tmpRect)                                            'select temp object to activate desired style name
                                            Threading.Thread.Sleep(500)                                     'required for COM lag (.NET only??)
                                            app.MenuActions.ItemByID(113159).Invoke()                       'Opens Style Options using "active" style... should work on styles
                                            tmpRect.Delete()                                                'deletes temporary object
                                            aDoc.Select(curSelections)                                      'restore previously selected items
                                            app.Panels("$ID/ObjStylesTreeViewPanelName").Visible = False    'close styles panel
                                    
                                    • 15. Re: Re: Re: How to Open/Display an Object Styles Style Name Menu
                                      ThinkingThings Level 1

                                      Addendum: Line 18 requires a separate MenuAction for each style...  here's the list:

                                       

                                        8453        Character Styles
                                        8481        Paragraph Styles
                                      113159        Object Styles
                                      132104        Table Styles
                                      132127        Cell Styles
                                      

                                       

                                      Hope this helps! 
                                        -TT  :-)