13 Replies Latest reply on Feb 1, 2012 11:53 AM by Laubender

    extract textFrames from Group

    Pierre-RAFFA Level 1

      Hi,

      Is there a better way to extract textFrames from Group than ungroup the group,  group all the  items except TextFrames ?

       

      Pierre RAFFA.

        • 1. Re: extract textFrames from Group
          Techi Panda Level 2

          Hi Pierre-RAFFA

           

          I think I can assist you in this. Its possible to share some sample INDD file.

           

          arul

          • 2. Re: extract textFrames from Group
            Pierre-RAFFA Level 1

            The document has just to have a group with two Rectangle and a textFrame inside.

            And I want to delete the TextFrame from the group without ungroup all.

            • 3. Re: extract textFrames from Group
              Peter Kahrel Adobe Community Professional & MVP

              Did you try something like this:

               

              myDocument.myGroup.textFrames[0].remove();

               

              Peter

              • 4. Re: extract textFrames from Group
                Pierre-RAFFA Level 1

                Thanks for this command but i have to put these textFrames out of the group and not really delete them.

                Pierre RAFFA

                • 5. Re: extract textFrames from Group
                  Peter Kahrel Adobe Community Professional & MVP

                  In that case i think you need to ungroup and regroup.

                   

                  Peter

                  • 6. Re: extract textFrames from Group
                    [Jongware] Most Valuable Participant

                    Here is a way to move one single text frame out of a group. It's weird ... you cannot simply "kick it out" it seems.

                     

                    textframeid = app.activeDocument.groups[0].textFrames[0].id;
                    orggroup = app.activeDocument.groups[0].allPageItems;
                    app.activeDocument.groups[0].ungroup();
                    for (i=0; i<orggroup.length; i++)
                    if (orggroup[i].id == textframeid)
                    {
                      orggroup.splice(i);
                      break;
                    }
                    app.activeDocument.groups.add(orggroup);
                    
                    • 7. Re: extract textFrames from Group
                      [Jongware] Most Valuable Participant

                      Ah -- slightly more elegant, and it ejects *all* text frames:

                       

                      orggroup = app.activeDocument.groups[0].allPageItems;
                      app.activeDocument.groups[0].ungroup();
                      newgroup = [];
                      for (i=0; i<orggroup.length; i++)
                      if (!(orggroup[i] instanceof TextFrame))
                        newgroup.push(orggroup[i]);
                      app.activeDocument.groups.add(newgroup);
                      
                      • 8. Re: extract textFrames from Group
                        John Hawkinson Level 5
                        orggroup = app.activeDocument.groups[0].allPageItems;
                        

                        Doesn't this screw up nested groups?

                        • 9. Re: extract textFrames from Group
                          Laubender Adobe Community Professional & MVP

                          @John – I would not group/ungroup, but duplicate the text frame and remove the original one. This would not screw up nested groups.

                          Downside: you would not do that to threaded text frames!

                           

                          var _d = app.documents[0];
                          var _group = app.selection[0]; //The group is my selection!
                          
                          var _groupObjects = _group.allPageItems;
                          
                          var _idOfOriginals = [];
                          var _idOfDuplicates = [];
                          
                          //Duplicates all text frames of group if text frame is not threaded to another one.
                          for(var n=0;n<_groupObjects.length;n++){
                              if(_groupObjects[n] instanceof TextFrame && _groupObjects[n].parentStory.textContainers.length == 1){
                                  _idOfOriginals.push(_groupObjects[n].id);
                                  _idOfDuplicates.push(_groupObjects[n].duplicate().id);
                                  };
                              };
                          
                          if(_idOfOriginals.length != 0){
                              //Remove the grouped ones.
                              //Leaves nested groups intact.
                              for(var n=0;n<_idOfOriginals.length;n++){
                                  _d.pageItems.itemByID(_idOfOriginals[n]).remove();
                                  };
                          };
                          
                          //Do something with the duplicates:
                          if(_idOfDuplicates.length != 0){
                              for(var n=0;n<_idOfDuplicates.length;n++){
                                  _d.pageItems.itemByID(_idOfDuplicates[n])/* .doSomething() */
                                  };  
                              };
                          

                           

                          Uwe

                          • 10. Re: extract textFrames from Group
                            Peter Kahrel Adobe Community Professional & MVP

                            > duplicate the text frame and remove the original one

                             

                            Way to go!

                            • 11. Re: extract textFrames from Group
                              John Hawkinson Level 5

                              Wow, this is getting complicated. What's with the leading underscores?

                               

                              Anyhow, what's wrong with saving Group.pageItems.everyItem().getElements(), ungrouping, removing the item, and re-grouping?

                              • 12. Re: extract textFrames from Group
                                Laubender Adobe Community Professional & MVP

                                This ball goes to Pierre RAFFA ;-)

                                 

                                But generally speaking it could be unfortunate to destroy subgroups if you want to work with them in a later process.

                                Personally I like the idea not to touch things or reorder objects if it's not necessary.

                                 

                                Ok. In case you deal with threaded text frames you'll have no choice but ungroup, regroup without text frames.

                                 

                                The following script assumes a selected group with one or several text frames, one or several nested groups.
                                It will ungroup all groups of the selection, singles out the text frames and regroups all other objects in one group (this time without the leading underscores):

                                 

                                var sel = app.selection[0];
                                var selAllObjects = sel.allPageItems;
                                var objectsNotToGroupN = [];
                                var groupIDs = [];
                                
                                for(var n=0;n<selAllObjects.length;n++){
                                
                                    if(selAllObjects[n] instanceof Group || selAllObjects[n] instanceof TextFrame){
                                        objectsNotToGroupN.push(n);
                                        };
                                    if(selAllObjects[n] instanceof Group){
                                        groupIDs.push(selAllObjects[n].id);
                                        };
                                
                                    };
                                
                                for(var n=objectsNotToGroupN.length-1;n>=0;n--){
                                    selAllObjects.splice(objectsNotToGroupN[n],1);
                                    };
                                
                                sel.ungroup();
                                
                                for(var n=0;n<groupIDs.length;n++){
                                    app.documents[0].pageItems.itemByID(groupIDs[n]).ungroup();
                                    };
                                
                                app.documents[0].groups.add(selAllObjects);
                                

                                 

                                Uwe

                                 

                                Message was edited by: Laubender (removed a minor spelling error)

                                • 13. Re: extract textFrames from Group
                                  Laubender Adobe Community Professional & MVP

                                  Ok. It does not work with inline or anchored objects. I will correct that hopefully soon.

                                   

                                  Uwe