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

Selecting connected objects with extend script?

Explorer ,
Nov 14, 2016 Nov 14, 2016

Copy link to clipboard

Copied

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.

TOPICS
Scripting

Views

249

Translate

Translate

Report

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 ,
Nov 15, 2016 Nov 15, 2016

Copy link to clipboard

Copied

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.contents).isValid) {

    // Draw a keyline between the frame and the symbol

  }

}

Peter

Votes

Translate

Translate

Report

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
Advisor ,
Nov 15, 2016 Nov 15, 2016

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

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