I think this will get you close to what you want if I understand your request...
Script Steps:
- Store each artboard into an object with an empty array
- Iterate over all of the document page items
- First, check to see if the item is visible and if the item's parent layer is visible
- Then check to see if the item's visible bounds fit within the bounds of any artboard
In the end, you are left with an object consisting of each artboard name and an array of the visible items within its bounds.
As always, there are potential gotchas and edge cases (groups, clipping masks, etc.)this rough draft script won't cover. It really depends on how the files you are working with are structured. If you are always dealing with paths you may want to work with pathItems and not pageItems. and more could also cause issues.
For example, in your sample file, you have a group and when you run the script below, the group along with its child items are added to the array. You could catch this edge case and only add the group (skipping the child item) but what happens when you have a visible group with some child items visible and some others hidden?
Hopefully, this gets you headed in the right direction. Cheers!
var doc = app.activeDocument;
// get all artboards and create and object to hold their pageItems
var captured = {};
for (var i = 0; i < doc.artboards.length; i++) {
captured[doc.artboards[i].name] = [];
}
// go through all page items
var item;
for (var i = 0; i < doc.pageItems.length; i++) {
item = doc.pageItems[i];
// first check to see if the page item is visible and its parent layer is visible
if (!item.hidden && item.layer.visible) {
// then iterate over the captured artboards
var ab;
for (var j in captured) {
var ab = doc.artboards.getByName(j);
// and check if the item is within the artboard bounds
if (withinArtboardBounds(item.visibleBounds, ab.artboardRect)) {
captured[j].push(item);
}
}
}
}
// for example purposes, show the capture items for each artboard
for (var a in captured) {
alert(a + "\n" + captured[a]);
}
function withinArtboardBounds(itemVisibleBounds, artboardBounds) {
return (
itemVisibleBounds[0] >= artboardBounds[0] &&
itemVisibleBounds[1] <= artboardBounds[1] &&
itemVisibleBounds[2] <= artboardBounds[2] &&
itemVisibleBounds[3] >= artboardBounds[3]
);
}