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

JavaScript: return an array based on selection order

New Here ,
Feb 01, 2013 Feb 01, 2013

Copy link to clipboard

Copied

Hi everyone,

Is there a method to return an array of paths in the order they were selected, instead of their descending z-index (default behaviour)?

I'm writing a script that "connects" the centers of currently selected objects through a stroked path, and I want it to follow the order in which I select the objects, regardless of the stacking order.

Any help is much appreciated! Thanks.

George

TOPICS
Scripting

Views

2.1K
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
Adobe
Community Expert ,
Feb 01, 2013 Feb 01, 2013

Copy link to clipboard

Copied

unfortunately no, that's not possible.

Votes

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 ,
Feb 01, 2013 Feb 01, 2013

Copy link to clipboard

Copied

Couldn't you make a new array while selecting the objects and reorder them while doing this and then draw the new line from that array?

Votes

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 ,
Feb 01, 2013 Feb 01, 2013

Copy link to clipboard

Copied

I didn't get that Larry, you mean while selecting via scripting? I think he wants to select manually in the order he needs the objects to be.

Votes

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 ,
Feb 01, 2013 Feb 01, 2013

Copy link to clipboard

Copied

You're probably right. There's no real way to keep the selection order by scripting. Didn't someone once do a script for a dot-to-dot line.

Votes

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 ,
Feb 01, 2013 Feb 01, 2013

Copy link to clipboard

Copied

that's right, I think it was Jongware, but I think for that one, the dots were drawn in order, so the it still went by the stacking order...I guess.

Votes

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 ,
Feb 01, 2013 Feb 01, 2013

Copy link to clipboard

Copied

I wonder if it could be done in ID with an onEvent handler?

Votes

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
New Here ,
Feb 01, 2013 Feb 01, 2013

Copy link to clipboard

Copied

Thanks for the reply. Too bad it's not possible.

Just to better illustrate what I was trying to do, in case anyone else wonders:

arrayorder.jpg

Oh well, back to manually laying out paths then.

Votes

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 ,
Feb 01, 2013 Feb 01, 2013

Copy link to clipboard

Copied

is there more to it? if you're selecting each circle, isn't even easier to draw the line?

Votes

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
New Here ,
Feb 01, 2013 Feb 01, 2013

Copy link to clipboard

Copied

Well, it's not exactly easier, as the line has to pass through the center of each circle and it's easier to select circles than snapping the pen tool to smart guides in the center of each circle.

BUT actually it's a little more to it than that. See, considering some circles (e.g. o1, o2, o3...on), my script draws a line (and then shortens it somewhat) between the center points of o1-o2 , then between those of o2-o3, o3-o4 and so on.

It works nice and well if the z-index of the circles happens to coincide with the order in which they were selected (o1>o2>o3...>on OR o1<o2<o3...<on), but if not (o1>o2<o3>o4...>on) things go BAD.

See here an example (numbers represent the selection order):

arrayorder2.jpg

I would like to obtain the GOOD version regardless of z-index positions of circles. Any ideas on how to pull that off?

Votes

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 ,
Feb 01, 2013 Feb 01, 2013

Copy link to clipboard

Copied

I see, interesting challenge...hard to do with what Illustrator offers...I'll keep thinking, maybe someone else comes up with an ingenious idea.

Votes

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 ,
Feb 01, 2013 Feb 01, 2013

Copy link to clipboard

Copied

do you mind messing up the stacking order? if you don't, one semi automatic way to do it for now

1. create a temp layer

2. draw a temp object in that layer, and add a note to it, i.e. "temp" (without the quotes)

3. select something else

4. create an action and give it a shortcut key i.e. "F4"...start recording...

5. Ctrl+X to cut

6. in the action's flyout menu...Select Object...who's note is "temp"

7. Ctrl+F to paste in front

8. Stop recording

...basically the action moves the selected object to the temp layer, now select your first circle and press F4, select the second and press F4...keep doing it until you have moved all needed circles to the temp layer...

...select the circles in the temp layer and run your script.

Votes

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
Guru ,
Feb 02, 2013 Feb 02, 2013

Copy link to clipboard

Copied

This is untested an just off the top of my head… Not a simple thing to script without any events… What you may be able to do but Im not sure… Just an idea you may want to try…

Make a script palette that sits open when run… This could use bridgetalk to check the app selection at given intervals… When you've finished selecting objects… click a button to draw the lines…

This is NOT something I have tried before but is probably the only method available to you…

Votes

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
New Here ,
Feb 03, 2013 Feb 03, 2013

Copy link to clipboard

Copied

LATEST

After trying out different things, I ended with this compromise:

1.I have my script hotkeyed (F4) as an action.

2.where I know the z-index follows the selection order (usually when going from left to right / right to left on the same row, going from top to bottom / bottom to top), I select all the elements that need to be connected and hit F4. Selection order doesn't even matter, since the returned array is z-index based anyway, so I can quickly marquee-drag a selection, saving some time.

3.where I know the z-index "breaks", I resort to manually selecting 2 objects at a time and running the script.

Thanks everyone for their suggestions!

Votes

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