Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to ungroup all groups in a document?

Engaged ,
Nov 09, 2024 Nov 09, 2024

Why this script doesn't end? The idea is to ungroup all the groups in the doc. 

    var doc = app.activeDocument;
    var exit;

    while (true) {
        exit = true;

        app.executeMenuCommand("selectall");
        var sel = doc.selection;

        for (var i = 0; i < sel.length; i++) {
            var item = sel[i];
            if (item.typename === "GroupItem") {
                app.executeMenuCommand("ungroup");
                alert('ungrouped!');
                exit = false;
                break;
            }
        }

        while (doc.selection.length > 0) {
            app.executeMenuCommand('deselectall');
            app.redraw();
        }

        if (exit) break;
    }

    alert('exit while loop');
TOPICS
Scripting
851
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Nov 09, 2024 Nov 09, 2024

The reason is that in Illustrator, clipping masks are also a group.

Translate
Adobe
Engaged ,
Nov 09, 2024 Nov 09, 2024

The reason is that in Illustrator, clipping masks are also a group.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 09, 2024 Nov 09, 2024

Désolé @andyf65867865  mais votre script n'est pas correct, il comporte plusieurs fautes ou maladresses.

(entre autres, la boucle for peut être parcourue de nombreuses fois...)

 

var compound = true;
 app.executeMenuCommand("selectall");
 app.executeMenuCommand("ungroup");
     if (compound) {
      app.executeMenuCommand("noCompoundPath");
     }
   selection = null;

 

René

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 10, 2024 Nov 10, 2024
LATEST

@renél80416020Thanks for the comments, indeed one operator turns out to be unnecessary, forcing the for loop to run unnecessary times in the case of multiple outer groups. However, the compound path type is a separate type and it was not necessary to “parse” it. Also, note that the line `selection = null` should be followed with redraw otherwise it will not work correct. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines