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

Ungroup all from selection

New Here ,
Apr 16, 2024 Apr 16, 2024

Copy link to clipboard

Copied

Hello:) i was trying to find something which will help me to Ungroup everything from selection to be able to add it on Action. I cant use normal ungroup becuase if i use it few times (in case there is more groups in selection) then script is stopping becuase there are no groups. So i tried script like this:

var doc;

function getChildAll(obj) {
var childsArr = [];
for (var i = 0; i < obj.pageItems.length; i++) {
childsArr.push(obj.pageItems[i]);
}
return childsArr;
}

function ungroupSelection() {
var selection = doc.selection;
for (var i = 0; i < selection.length; i++) {
var item = selection[i];
if (item.typename == "GroupItem") {
var elements = getChildAll(item);
for (var j = 0; j < elements.length; j++) {
elements[j].moveBefore(item);
}
item.remove();
ungroupSelection(); // Recursively ungroup newly ungrouped items
}
}
}

if (app.activeDocument) {
doc = app.activeDocument;
if (doc.selection.length > 0) {
ungroupSelection();
} else {
alert("Please make a selection before running this script.");
}
} else {
alert("Please open a document before running this script.");
}


Script is working but its showing me error like in attachment. How i can avoid it? or maybe there is some easier way to ungroup everything from selection?

TOPICS
Scripting

Views

109

Translate

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
Adobe
Enthusiast ,
Apr 17, 2024 Apr 17, 2024

Copy link to clipboard

Copied

LATEST

You may find the ExtUngroup script useful. Choose Target > Selected objects and Options > Ungroup all.

Votes

Translate

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