19 Replies Latest reply on Jan 2, 2017 8:05 AM by Trevorׅ

    find text frame behind rectange

    keyank99503373

      how to group if any text frame behind rectangle frame.

       

       

      Capture.GIF

        • 1. Re: find text frame behind rectange
          Laubender Adobe Community Professional & MVP

          Can you please be more specific?

          Do you want to find text frames with captions or photographer's credits and the corresponding image?

           

          Didn't we have something like that a few days before?

          As a starter see here where Stefan Rakete gave the answer not to the same but to a similar problem:

          Re: Find Image Name

           

          Regards,

          Uwe

          • 2. Re: find text frame behind rectange
            keyank99503373 Level 1

            There is no relation between image and credit text frame. But i need to find credit text frame and both to be grouped.

            • 3. Re: find text frame behind rectange
              tpk1982 Level 4

              AS Uwe said, you have to check the geometric bounds for both image and text frame.. if it overlapped then need to group... the link he provided give the idea to proceed further

              • 4. Re: find text frame behind rectange
                keyank99503373 Level 1

                I used to place the image and caption in front of textframe using wrap property and i have one another text frame in front of image. I need to find only those credit frame and group along with caption and image. also i am going to export all things as image i wrote that concept.

                 

                when i export the same as image i need to include credit frame

                • 6. Re: find text frame behind rectange
                  tpk1982 Level 4

                  See the group caption with image option in right bottom corner

                   

                  Screen Shot 2016-12-30 at 12.47.18 PM.png

                  • 7. Re: find text frame behind rectange
                    keyank99503373 Level 1

                    I need solution to find the textframe behind the graphic frame.

                    • 8. Re: find text frame behind rectange
                      tpk1982 Level 4

                      In this forum basically they will help you.. and not work for you.. try to write some codings and then ask help here.. definitely you will get answer from experts ..

                      • 9. Re: find text frame behind rectange
                        keyank99503373 Level 1

                        Please don't take this other way. Thanks you so much karthi.

                        • 10. Re: find text frame behind rectange
                          keyank99503373 Level 1

                          I don't know how to do this. if there is any option to find the behind object in javascript

                          • 11. Re: find text frame behind rectange
                            tpk1982 Level 4

                            I have been in this forum for nearly 6 years.. this is how it works.. so guided you.. don't take it as personal..

                            • 12. Re: find text frame behind rectange
                              Trevorׅ Adobe Community Professional

                              This should help

                              Select the picky.

                              Trevor

                              // jshint undef: true, unused: true
                              var stopIfNot, picky, spread, spreadItems, l, itemsToTestForBounds, item, itemBounds, itemsToGroup, pickyBounds;
                              
                              stopIfNot = function(condition, message) {
                                  if (!condition) {
                                      if (message) {
                                          alert(message);
                                      }
                                      exit();
                                  }
                              };
                              
                              picky = spread = app.selection[0];
                              stopIfNot(spread, 'No Selection');
                              ///////////////////////////
                              // Get the parent spread //
                              ///////////////////////////
                              while (spread.constructor !== Spread) {
                                  spread = spread.parent;
                                  if (spread.constructor === Document) {
                                      spread = false;
                                      break;
                                  }
                              }
                              stopIfNot(spread, 'No Spread found');
                              ///////////////////////////////////////////
                              // Get objects behind the selected order //
                              ///////////////////////////////////////////
                              
                              spreadItems = spread.allPageItems;
                              l = spreadItems.length - 1;
                              itemsToTestForBounds = [];
                              while ((item = spreadItems[l--]) !== picky) {
                                  if (item.parent.constructor !== Spread) {
                                      continue; // only want out objects
                                  }
                                  itemsToTestForBounds.push(item);
                              }
                              if (itemsToTestForBounds.length) {
                                  itemsToTestForBounds.push(picky);
                              }
                              itemsToGroup = [];
                              pickyBounds = picky.geometricBounds;
                              
                              ///////////////////////
                              // test for overlaps //
                              ///////////////////////
                              
                              l = itemsToTestForBounds.length;
                              while (l--) {
                                  item = itemsToTestForBounds[l];
                                  itemBounds = item.geometricBounds;
                                  if (!(itemBounds[0] > pickyBounds[2] ||
                                          itemBounds[2] < pickyBounds[0] ||
                                          itemBounds[1] > pickyBounds[3] ||
                                          itemBounds[3] < pickyBounds[1])) {
                                      itemsToGroup.push(item);
                                  }
                              }
                              
                              ////////////////////////////
                              // Group overlapped items //
                              ////////////////////////////
                              
                              newGroup = app.activeDocument.groups.add(itemsToGroup, picky.itemLayer);
                              
                              • 13. Re: find text frame behind rectange
                                Laubender Adobe Community Professional & MVP

                                Hi Keyank,

                                Trevor's script is a very good start.

                                 

                                You have to adapt it to your needs:

                                 

                                1. Single out text frames. You can do this e.g. in line 33 or 34.

                                2. Currently the scope of the script is a selected item on the page.

                                Maybe you do not want to work with that, but perhaps with all graphic frames that contain images on a page.

                                Or on all pages of a spread. Or running a loop through all pages of your document and testing graphic frames that contain images …

                                3. You should add a try/catch around line 65.

                                itemsToGroup could only contain one item—the one you selected—if no item is found stacked behind the selected one.

                                 

                                Regards,
                                Uwe

                                1 person found this helpful
                                • 14. Re: find text frame behind rectange
                                  Trevorׅ Adobe Community Professional

                                  Hi Uwe

                                   

                                  It cant contain 1 item but it could contain none so could do

                                  if (itemsToGroup.length) {newGroup = app.activeDocument.groups.add(itemsToGroup, picky.itemLayer)};

                                   

                                  Trevor

                                  1 person found this helpful
                                  • 15. Re: find text frame behind rectange
                                    Trevorׅ Adobe Community Professional

                                    See line 39

                                    • 16. Re: find text frame behind rectange
                                      keyank99503373 Level 1

                                      Is there is any default function find the stack order ?

                                      • 17. Re: find text frame behind rectange
                                        Laubender Adobe Community Professional & MVP

                                        Thanks for the hint, Trevor.

                                         

                                        To Keyank:

                                        Where is the problem?

                                         

                                        There is no default function to find all items stacked below a selected item.

                                        All we can tell is the stacking order of all page items in a spread.

                                        Not in a page. In a spread. And that would also include items on the pasteboard.

                                        spread.allPageItems is the array where the items are stored in stacking order.

                                        From top to bottom.

                                         

                                        Have a document with one page where an image is placed.

                                        Stacked below is a text frame.

                                         

                                        Run this snippet:

                                         

                                        var spreadOneItems = app.documents[0].spreads[0].allPageItems;
                                        for(var n=0;n<spreadOneItems.length;n++){$.writeln(n+"\t"+spreadOneItems[n])};
                                        

                                         

                                        Result will be something like that:

                                         

                                        0    [object Rectangle]
                                        1    [object Image]
                                        2    [object TextFrame]
                                        

                                         

                                        Group all items on the spread—the rectangle (that contains the image) and the text frame stacked below—and run the snippet again.

                                        Result will be:

                                         

                                        0    [object Group]
                                        1    [object Rectangle]
                                        2    [object Image]
                                        3    [object TextFrame]
                                        

                                         

                                        Regards,
                                        Uwe

                                        • 18. Re: find text frame behind rectange
                                          keyank99503373 Level 1

                                          Now I am very clear. Thank you so much.

                                          • 19. Re: find text frame behind rectange
                                            Trevorׅ Adobe Community Professional

                                            Hi

                                             

                                            This would be a generic function for sorting an array of pageItems (all belonging to the same spread) by stack order.

                                             

                                            // Order an array page items by z stacking order
                                            // by Trevor http://creative-scripts.com
                                            
                                            // jshint undef: true, unused: true
                                            /* globals app, $, MeasurementUnits, ContentType, Spread, Document */
                                            
                                            var orderByStack;
                                            orderByStack = function(pageItems) {
                                            
                                                var spread, allSpreadItems, n, c, item,
                                                    stackMap = [];
                                            
                                                ////////////////////////////////////////////////////////////////////////////////////////
                                                // Get the parent spread                                                              //
                                                // We're going to be lazy and not check that all the pageItems are on the same spread //
                                                // If there not then a deserved error will be thrown                                  //
                                                ////////////////////////////////////////////////////////////////////////////////////////
                                            
                                                spread = pageItems[0];
                                            
                                                while (spread.constructor !== Spread) {
                                                    spread = spread.parent;
                                                    if (spread.constructor === Document) {
                                                        spread = false;
                                                        return pageItems; // spit back the same spit that was spat
                                                    }
                                                }
                                                allSpreadItems = spread.allPageItems;
                                                n = allSpreadItems.length;
                                                //////////////////////////////////
                                                // Index the spread items by Id //
                                                //////////////////////////////////
                                                for (c = 0; c < n; c++) {
                                                    item = allSpreadItems[c];
                                                    stackMap['_' + item.id] = {
                                                        index: c,
                                                        item: item
                                                    };
                                                }
                                            
                                                //////////////////////////////////////////////////////////////////////////////////
                                                // make a temp non-sorted list of the pageItems that contains there stack index //
                                                //////////////////////////////////////////////////////////////////////////////////
                                            
                                                n = pageItems.length;
                                                for (c = 0; c < n; c++) {
                                                    pageItems[c] = stackMap['_' + pageItems[c].id];
                                                }
                                            
                                                /////////////////////////////////////
                                                // Sort the stackList by stack order //
                                                /////////////////////////////////////
                                            
                                                pageItems.sort(function(a, b) {
                                                    return b.index < a.index;
                                                });
                                            
                                                while (n--) {
                                                    pageItems[n] = pageItems[n].item;
                                                }
                                            
                                                allSpreadItems.length = 0;
                                                return pageItems;
                                            };
                                            
                                            
                                            
                                            /////////////////
                                            // Pretty Demo //
                                            /////////////////
                                            
                                            
                                            var doc, itemsToCheck = [],
                                                n, madeItems = [];
                                            doc = app.documents.add({
                                                viewPreferences: {
                                                    horizontalMeasurementUnits: MeasurementUnits.MILLIMETERS,
                                                    verticalMeasurementUnits: MeasurementUnits.MILLIMETERS
                                                }
                                            });
                                            var swatchCount, itemsToMake, top, left, bottom, right, rn, item, s, rn, color;
                                            swatchCount = doc.swatches.length - 1;
                                            
                                            /////////////////////
                                            // Make some items //
                                            /////////////////////
                                            
                                            itemsToMake = 15;
                                            while (itemsToMake--) {
                                                top = 10 + (260 * Math.random()) | 0;
                                                left = 10 + (180 * Math.random()) | 0;
                                                bottom = top + 40 + 100 * Math.random() | 0;
                                                right = left + 40 + 100 * Math.random() | 0;
                                                madeItems.push(doc.pages[0].rectangles.add({
                                                    geometricBounds: [top, left, bottom, right],
                                                    fillColor: 'None',
                                                    strokeColor: doc.swatches[-1],
                                                    transparencySettings: {
                                                        blendingSettings: {
                                                            opacity: 70
                                                        }
                                                    }
                                                }));
                                            }
                                            
                                            ////////////////////////////////
                                            // randomly pick some of them //
                                            ////////////////////////////////
                                            
                                            n = 5;
                                            while (n--) {
                                                rn = madeItems.length * Math.random() | 0;
                                                itemsToCheck.push(madeItems[rn]);
                                                madeItems.splice(rn, 1);
                                            
                                            }
                                            
                                            ///////////////////////////////////////////////////////////
                                            // we now have 5 items that are of a random stack order. //
                                            // Let's order them                                      //
                                            ///////////////////////////////////////////////////////////
                                            
                                            orderByStack(itemsToCheck);
                                            
                                            ///////////////////////////
                                            // Lets make them pretty //
                                            ///////////////////////////
                                            
                                            n = itemsToCheck.length;
                                            s = 0;
                                            $.writeln('back');
                                            while (n--) {
                                                item = itemsToCheck[n];
                                                s = s % swatchCount + 1;
                                                color = doc.swatches[swatchCount - s];
                                                item.fillColor = color;
                                                item.contentType = ContentType.TEXT_TYPE;
                                                item = item.getElements()[0];
                                                item.contents = '' + (n + 1);
                                                $.writeln('item.itemByID(' + item.id + ').color.name: ' + color.name + ' contents: ' + item.contents);
                                            }
                                            $.writeln('front');