Skip navigation
Currently Being Moderated

total ungroup?

Jun 26, 2012 9:57 PM

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?

 
Replies
  • Currently Being Moderated
    Jun 26, 2012 10:24 PM   in reply to arjun2

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

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 27, 2012 3:00 AM   in reply to arjun2

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 27, 2012 3:23 AM   in reply to Peter Spier

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 27, 2012 3:33 AM   in reply to Petteri_Paananen

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

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 27, 2012 8:28 AM   in reply to Peter Spier

    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...

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 27, 2012 4:31 AM   in reply to arjun2

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 27, 2012 6:12 AM   in reply to Marijan Tompa

    @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

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 27, 2012 6:23 AM   in reply to Laubender

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 27, 2012 7:53 AM   in reply to Laubender

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

     

    Uwe

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 27, 2012 8:30 AM   in reply to Laubender

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

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 28, 2012 1:54 PM   in reply to arjun2

    @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

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points