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

ungroup and group objects

Participant ,
Feb 04, 2019 Feb 04, 2019

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.

TOPICS
Scripting
2.4K
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

Community Expert , Feb 04, 2019 Feb 04, 2019

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

...
Translate
Community Expert ,
Feb 04, 2019 Feb 04, 2019

Paste the code you have and mention the exact issue that code is having so that we can build over that.

-Manan

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
Participant ,
Feb 04, 2019 Feb 04, 2019

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"); 

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
Community Expert ,
Feb 04, 2019 Feb 04, 2019

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

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
Community Expert ,
Feb 04, 2019 Feb 04, 2019

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

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
Participant ,
Feb 04, 2019 Feb 04, 2019

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.

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
Participant ,
Feb 04, 2019 Feb 04, 2019
LATEST

its work like a charm

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