forked from johnwun/js4ai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SelectReplicatedText.js
79 lines (71 loc) · 2.08 KB
/
SelectReplicatedText.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/////////////////////////////////////////////////////////////////
//Select Replicated (Overlaping) Text Items v.1 -- CS,CS2
//>=--------------------------------------
// This script removes all duplicate overlaping text items from a document.
// The ONLY parameters it checks are top and left coordinates, and text contents.
// Anchor points within one point of each other are considered the same.
// (tolerance can be adjusted by changing the 'tolerance' value.)
//
// The lower duplicate objects are selected for manual removal.
//
//>=--------------------------------------
// JS code (c) copyright: John Wundes ( [email protected] ) www.wundes.com
//copyright full text here: http://www.wundes.com/js4ai/copyright.txt
//////////////////////////////////////////////////////////////////
var selName = "document";
if(selection.length >0){
selName = "current selection";
var sel= activeDocument.selection;
var selectedTextFrames = new Array(0);
for (var all in sel){
if(sel[all].typename == "TextFrame"){
selectedTextFrames.push(sel[all]);
}
}
sel = selectedTextFrames;
} else{
var sel= activeDocument.textFrames;
}
var dupeTextFrames= new Array(0);
var tolerance = 1;
var slen = sel.length;
for(var all=0; all <slen;all++){
checkDupe(sel,all);
}
//
alert(dupeTextFrames.length + " duplicate Text items found in "+selName+".");
if(dupeTextFrames.length>0){
activeDocument.selection = [];
for (all in dupeTextFrames){
dupeTextFrames[all].selected = true;
}
}
//---------------------------------------
function checkDupe(ob,n){
//t == objects so far
for(var t=0; t <n ;t++){
if(ob[t].typename == "TextFrame"){
if (isWithin(ob[n].left,ob[t].left,tolerance) &&
isWithin(ob[n].top,ob[t].top,tolerance) &&
ob[n].contents == ob[t].contents){
dupeTextFrames.push(ob[n]);
break;
}
}
}
}
function isWithin(YposA,YposB,tol){
if(YposA==YposB){return true};
if(findDiff(YposA,YposB)<tol){
return true;
}
return false;
}
function findDiff(a,b){
if( a>0 && b>0 && b>a ||
a<0 && b>0 ||
a<0 && b<0 && a>b ){
return Math.abs(b-a);
}
return Math.abs(a-b);
}