For a line the following holds true (but not many other shapes). Center of bounding box is equal to center of line. Now if we simply modify this script:
#target illustrator
var doc = app.activeDocument;
var sel = doc.selection;
var rad = 10;
for(var i = 0; i < sel.length; i++){
if(sel[i].typename == "PathItem"){
var obj = sel[i];
var center = obj.position;
center[0] += obj.width/2.0;
center[1] -= obj.height/2.0;
doc.pathItems.ellipse(
center[1]+rad,center[0]-rad,
2*rad, 2*rad,
false, false
);
}
}
Select red lines and run (with extendScript Toolkit).
Or you can do this fully automatically without a script just select the red lines:
- (optional, see below) duplicate them
- apply convert to shape ellipse, set values to absolute.
- (optional) Expand
done. Alternatively you can just add another stroke on the line with a ellipse conversion, then no duplicate is needed