Here’s one way to do it:
assuming I want to check three layers that are layers 1, 2, and 3 and see if their position is less than 100 pixels form my target layer.
I’m also assuming non of these layers are parented for now.
I would give the text-layer’s sourceText property this expression:
num = 0;
for (i=1; i<4; i++) {
if (length(thisComp.layer(i).position - thisComp.layer("target").position)<100) {
num++;
}
}
num;
This straight line distance works better for 100×100 circles. You could change it to <1 and it will only count if they are at the exact same location.
For squares that are all 100×100 pixels this kind of check is maybe better:
num = 0;
for (i=1; i<4; i++) {
if (
Math.abs(thisComp.layer(i).position[0] - thisComp.layer("target").position[0])<100
&&
Math.abs(thisComp.layer(i).position[1] - thisComp.layer("target").position[1])<100
) {
num++
}
}
num