2 Replies Latest reply on Nov 15, 2016 6:24 AM by Vamitul

    Selecting connected objects with extend script?

    Bill McLean

      Give I have the document with multiple text frames (orange with text) and a number of lines and small shapes (black circles or orange small squares:

       

      Bounding.png

      Some of the rules are:

      • A text frame is connected with a keyline if the either end point of a line lies within the bounding box of the text frame.
      • A symbol (small black-filled circle or orange filled square) is connected with the text frame.
      • A line crossing under another is not connected.

      There is a brute force solution to this problem where I create an array of text frames, an array of point objects (for the lines) and an array of shapes. Sort each array by x  coordinates and y coordinates.  Traverse the points array (line start and end points) and see what objects/text frames contain the points.

      Is there a more elegant solution where I can leverage the selection engine.

        • 1. Re: Selecting connected objects with extend script?
          Peter Kahrel Adobe Community Professional & MVP

          I would do it like this:

          If a symbol needs to be connected to a text frame with a keyline, name the symbol on the Layers panel, using the text frame's content for the name.

          Then cycle through the text frames. For each text frame, if there is a named symbol, draw a keyline on the fly from the text frame to the symbol.

           

          for (i = 0; i < frames.length; i++) {
            if (myDoc.pageItems.item(frames[i].contents).isValid) {
              // Draw a keyline between the frame and the symbol
            }
          }
          

           

          Peter

          • 2. Re: Selecting connected objects with extend script?
            Vamitul Level 4

            I don't see any other approach except for "brute force". You can fine-tune it a bit, however:

            1) function isConnected(line,symbolOrTextFrame){return Boolean}
            2) arrayOfLines

            3) arrayOfTextFramesAndSymbols

             

            iterate through the lines array, for each find the connected object, then remove the found connected object form it's array.