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

How to ungroup all groups in a document?

Engaged ,
Nov 09, 2024 Nov 09, 2024

Copy link to clipboard

Copied

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

Views

361
Translate

Report

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.

Votes

Translate
Engaged ,
Nov 09, 2024 Nov 09, 2024

Copy link to clipboard

Copied

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

Votes

Translate

Report

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

Copy link to clipboard

Copied

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é

Votes

Translate

Report

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

Copy link to clipboard

Copied

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. 

Votes

Translate

Report

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