Copy link to clipboard
Copied
I need a script that draws line (stroke: 1, yellow) between center of two randomly placed <Ellipse> objects on the artboard. Ellipses size is 10x10 and they cannot be symbols. Elipses cannot have different names, there name should be <Ellipse> .
My goal is to select the two green ellipses, run the script and get the line between the centers.
End goal example:
 
2 Correct answers
You may use this action:
Instruction:
- Download and unzip the file
- In the Actions palette, import the action set connector_1.aia
- Select two circles (or any other shape)
- Run the action connector_1
// select 2 ellipses
var s = app.selection;
var path1 = activeDocument.pathItems.add();
path1.setEntirePath([[s[0].left + s[0].width / 2, s[0].top - s[0].height / 2],
[s[1].left + s[1].width / 2, s[1].top - s[1].height / 2]]);
var color1 = new RGBColor;
color1.red = color1.green = 255;
color1.blue = 0;
path1.strokeColor = color1;
path1.strokeWidth = 1;
Explore related tutorials & articles
Copy link to clipboard
Copied
You may use this action:
Instruction:
- Download and unzip the file
- In the Actions palette, import the action set connector_1.aia
- Select two circles (or any other shape)
- Run the action connector_1
Copy link to clipboard
Copied
Thank you!
It worked properly besides it makes the line green.
Thank you for the fast response!
Quick question. Do you think the action can be modified for the line to be yellow and below the two selected circles?
Thank you in advance for your time! You are amazing. 🙂
Copy link to clipboard
Copied
Copy link to clipboard
Copied
// select 2 ellipses
var s = app.selection;
var path1 = activeDocument.pathItems.add();
path1.setEntirePath([[s[0].left + s[0].width / 2, s[0].top - s[0].height / 2],
[s[1].left + s[1].width / 2, s[1].top - s[1].height / 2]]);
var color1 = new RGBColor;
color1.red = color1.green = 255;
color1.blue = 0;
path1.strokeColor = color1;
path1.strokeWidth = 1;
Copy link to clipboard
Copied
Thank you for the script and your time! Have in mind that something does not work in it. But I already got a solution to my problem from the previous comment.
Thank you again for your time I really appreciate it!
Copy link to clipboard
Copied
Have in mind that something does not work in it.
By D.S..
your top layer must be visible and unlocked to avoid that error
Copy link to clipboard
Copied
Ok I have tested it and it is working the way you mentioned.
Thank you! 🙂
Copy link to clipboard
Copied
Is it possible to modify the script to lock the line only after creating it?
Copy link to clipboard
Copied
here you go
// select 2 ellipses
var s = app.selection;
var path1 = activeDocument.pathItems.add();
path1.setEntirePath([[s[0].left + s[0].width / 2, s[0].top - s[0].height / 2],
[s[1].left + s[1].width / 2, s[1].top - s[1].height / 2]]);
path1.move (s[s.length-1], ElementPlacement.PLACEAFTER);
var color1 = new RGBColor;
color1.red = 255;
color1.green = 255;
color1.blue = 0;
path1.strokeColor = color1;
path1.strokeWidth = 1;
path1.locked = true;

