Copy link to clipboard
Copied
I need to ungroup and the resize one of the object inside the group
And group it again. When I do that if the group object has images its not getting grouped how to solve this.
I did a quick test with a group containing an image and two textframes and the following worked for me. Please note that no error checking is used, it just demonstrates the code that works for me
...var firstGraphic = app.activeDocument.groups[0].allGraphics[0]
var pg = app.activeDocument.groups[0].pageItems.everyItem().getElements()
//Ungroup
app.activeDocument.groups[0].ungroup()
//Resize the graphic frame
firstGraphic.parent.visibleBounds = [firstGraphic.parent.visibleBounds[0], firstGraphic.parent.vi
Copy link to clipboard
Copied
Paste the code you have and mention the exact issue that code is having so that we can build over that.
-Manan
Copy link to clipboard
Copied
I am going to use the below code which it s copied from forum itself. When I do the testing process its not working if the group has images
main();
exit();
function main() {
var orgGroup;
// test if the seleted item is a Group
if ((app.selection.length > 0) && (app.selection[0].constructor.name == "Group")) {
alert("Info\nGroup selected");
orgGroup = app.activeDocument.groups[0].allPageItems;
app.activeDocument.groups[0].ungroup();
alert("Info\nUngrouped the selected group");
// call your function(s)
yourStuff();
}
else {
alert("Warning\nNo group selected");
orgGroup = "";
}
if (orgGroup != "") {
newgroup = [];
for (i=0; i<orgGroup.length; i++) newgroup.push(orgGroup);
app.activeDocument.groups.add(newgroup);
alert("Info\nRegrouped previous grouped Items");
}
alert("Info\nI did my job, what about yours?");
}
function yourStuff() {
alert ("Info\nDo your stuff here");
}
Copy link to clipboard
Copied
The issue with the code that you are using is that its using allPageItems collection of group that is considering an image as 2 objects one a rectangle and other an image. However when these objects are passed to the group function it crashes, seems it does not need children of an object when the parent is already in the collection. Using pageItems as i have used does not have this issue.
Try it and let us know the results.
-Manan
Copy link to clipboard
Copied
I did a quick test with a group containing an image and two textframes and the following worked for me. Please note that no error checking is used, it just demonstrates the code that works for me
var firstGraphic = app.activeDocument.groups[0].allGraphics[0]
var pg = app.activeDocument.groups[0].pageItems.everyItem().getElements()
//Ungroup
app.activeDocument.groups[0].ungroup()
//Resize the graphic frame
firstGraphic.parent.visibleBounds = [firstGraphic.parent.visibleBounds[0], firstGraphic.parent.visibleBounds[1], firstGraphic.parent.visibleBounds[2] + 5, firstGraphic.parent.visibleBounds[3] + 5]
//Regroup all the items
app.activeDocument.groups.add(pg)
-Manan
Copy link to clipboard
Copied
Thanks you so much. Its working fine.
Now I replaced groups[0].allPageItems; to groups[0].pageItems.everyItem().getElements().
Just I want to know what is the difference between two comments.
Copy link to clipboard
Copied
its work like a charm