13 Replies Latest reply: Jun 29, 2012 3:59 AM by arjun2 RSS

    total ungroup?

    arjun2 Community Member

      how can i ungroup a set of objects completely?

       

      for example i have a group of 2 rectangles, a group of 3 circles. i then make a single group of these two groups. now when i ungroup i get 2 groups. i want to ungroup in such a way, that the objects get ungrouped totally without any native groups. i know if i do the ungroup command again i'll get what i want. but is there a quicker way?

        • 1. Re: total ungroup?
          Scott Falkner Community Member

          I just press Command-Shift-G a few times. Your fingers are already on the keys, just fan the G like Clint Eastwood.

          • 2. Re: total ungroup?
            Peter Spier ACP/MVPs

            You can ask in scripting if there's a way to do a loop to ungroup nested groups. You can assign any keyboard shortcut to a script that you like, so you could either have the regualr shorcut reassigned, or have the best of both worlds and have two shorcuts, one for total groupd destruction, and one for simple fractures.

            • 3. Re: total ungroup?
              Petteri_Paananen Community Member

              Here´s one:

              https://dl.dropbox.com/u/17227987/unGroupAll.jsx.zip

               

              But it really ungroups all in your document...

              Script is modified from this thread:

              http://forums.adobe.com/thread/689941

              • 4. Re: total ungroup?
                Peter Spier ACP/MVPs

                Can you modify it to work on just a selection, rather than the whole document?

                • 5. Re: total ungroup?
                  Petteri_Paananen Community Member

                  I´m afraid my scripting skills are not very "mad"...=)

                  Here´s the version that ungroups only items in active page...

                  https://dl.dropbox.com/u/17227987/unGroupPage.jsx.zip

                   

                  Big guys from scripting forum probably can do a selection based ungrouping script in a snap...

                  • 6. Re: total ungroup?
                    Marijan Tompa [tomaxxi] UGM-MVPs

                    Hi,

                     

                    This should work:

                     

                    var
                        _nG = ( app.documents.length < 1 || app.selection.length < 1 ?
                            ( alert ( "Please select something first!", "Error!", true ), exit () ) :
                            ( app.selection.length > 1 ?
                                app.documents [ 0 ].groups.add ( app.selection ) :
                                ( app.selection [ 0 ] instanceof Group ?
                                    app.selection [ 0 ] :
                                    exit ()
                                )
                            )
                        );
                    
                    do {
                        for ( var i = 0 ; i < _nG.allPageItems.length ; i++ )
                            if ( _nG.allPageItems [ i ] instanceof Group )
                                _nG.allPageItems [ i ].ungroup ();
                         if ( _nG.allPageItems.toSource ().indexOf ( "group" ) == -1 )
                            break;
                    } while ( -1 );
                    
                    _nG.ungroup();
                    

                     

                    Hope that helps.

                     

                    --

                    Marijan (tomaxxi)

                    http://tomaxxi.com

                    • 7. Re: total ungroup?
                      Laubender MVP

                      @Marijan – I see one potential problem with that script: how to deal with groups that are inserted into text frames and therefor cannot be ungrouped?
                      Anchored groups seem to be a problem. The script will throw an error: "Invalid object for this request".

                       

                      And another one: if the selection consists of two groups, one locked, the other un-locked, the script will throw an error as well: "Invalid parameter".

                       

                      But there is also a  side effect I consider as cool: if it happens to be that there is a group that is locked (and that is all you selected), you'll get that group not only un-grouped, but also all parts of it are locked (again ?) after script execution.

                       

                      So instead of trying to debug the script, I wrote another one with a different concept in mind:

                       

                      1. count all pageItems of your selection and
                      2. try to invoke the menu command for "ungroup" that many times
                      In case the menu command is not available anymore, break the loop

                       

                      I think I saw a difference of output, if my script is used in InDesign CS5.5 against CS6:
                      In CS5.5 a locked group will be un-grouped, all items formerly in that group will be locked after execution
                      In CS6 a locked group will be un-grouped, but all items stay un-locked (like they were, before beeing grouped)

                       

                      Here is my script with invoke menu command:

                       

                      //UngroupAllGroupsOfSelection_SNIPPET.jsx
                      //Uwe Laubender
                      /**
                      * @@@BUILDINFO@@@ UngroupAllGroupsOfSelection_SNIPPET.jsx !Version! Wed Jun 27 2012 15:11:27 GMT+0200
                      */
                      //DESCRIPTION: Ungroups all groups of selection by invoking the menu "ungroup" as much as necessary; undo in one go!
                      
                      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
                      
                      app.doScript(_UngroupAllGroupsOfSelection, ScriptLanguage.JAVASCRIPT, [], UndoModes.ENTIRE_SCRIPT, "Ungroup all groups of selection, if possible.");
                      
                      function _UngroupAllGroupsOfSelection(){
                      
                      if(app.selection.length===0){alert("You selected nothing. Select something you want to ungroup!");exit(0);};
                      
                      //Check how many page items are in the selection:
                      var counter = 0;
                      for(var n=0;n<app.selection.length;n++){
                          counter = counter + app.selection[n].allPageItems.length;
                          };
                      //"counter" is the max number of "ungroup" actions we need:
                      for(var n=0;n<counter;n++){
                          //Invoke menu action: "Ungroup" until the menu action is not available any more:
                          try{app.scriptMenuActions.itemByID(118845).invoke()}catch(e){break};   
                          };
                      
                      }; //END function "_UngroupAllGroupsOfSelection()"
                      

                       

                      Uwe

                      • 8. Re: total ungroup?
                        Laubender MVP

                        I could imagine one special case my script would fail:

                        A selection of one single group that consists of only one single object. But that is nothing you can "achieve" in the normal UI of InDesign; a group has to consist by at least two page items. However by scripting you can get a group with only one page item inside.

                         

                        Uwe

                        • 9. Re: total ungroup?
                          Laubender MVP

                          Forget what I wrote in answer #8. My script is working on groups with just one element.

                           

                          Uwe

                          • 10. Re: total ungroup?
                            Petteri_Paananen Community Member

                            What did I say ...=) (about guys from scripting forum)

                            • 11. Re: total ungroup?
                              arjun2 Community Member

                              how should i use these language scripts. how can i create one?

                              • 12. Re: total ungroup?
                                Laubender MVP

                                @arjun2 – basically you save the code (text only) in a text file.

                                 

                                Name it with a .jsx suffix, that indicates the script is of JavaScript flavour and put it (in case of my script) into the Scripts/Scripts Panel folder. After that you can instantly access the script in the Scripts Panel of InDesign. Double-click the script there and it will instantly execute.

                                 

                                You can add subfolders to the "Scripts Panel" folder to organize your scripts.

                                 

                                Uwe

                                • 13. Re: total ungroup?
                                  arjun2 Community Member

                                  oh i see ..thanks