-
Notifications
You must be signed in to change notification settings - Fork 56
/
batchParent.jsx
87 lines (69 loc) · 2.39 KB
/
batchParent.jsx
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
80
81
82
83
84
85
86
87
//Batch parent layers
//1. select the batch you want to set parents to
//2. select the batch you want to parentthe first batch to
//order matters
//0.1 - initial release
//CC-BY-SA, Nik Ska, 2013
var nsBatchParent = this;
this.version = 0.1;
this.scriptTitle = "Batch Parent";
nsBatchParent.run = function(){
this.buildGUI(this);
}
nsBatchParent.thisBatch = [];
nsBatchParent.thatBatch = [];
nsBatchParent.buildGUI = function(thisObj){
thisObj.w = (thisObj instanceof Panel) ? thisObj : new Window("palette", thisObj.scriptTitle, undefined, {resizeable:true});
thisObj.w.alignChildren = ['left', 'top']
var l1 = thisObj.w.add("group{orientation:'row', alignChildren: ['left', 'top']}");
l1.add("staticText", undefined, "Parent");
l1.margins = [0,0,0,0];
var thisBttn = l1.add("button", undefined, "this");
thisBttn.size = [40, 20];
var l2 = thisObj.w.add("group{orientation:'row', alignChildren: ['left', 'top']}");
var toTxt = l2.add("staticText", undefined, " to");
toTxt.size = [33,20];
l2.margins = [0,0,0,0];
var thatBttn = l2.add("button", undefined, "that");
thatBttn.size = [40, 20];
thisBttn.onClick = function(){
thisObj.getThis(thisObj);
}
thatBttn.onClick = function(){
thisObj.getThat(thisObj);
}
if (thisObj.w instanceof Window){
thisObj.w.center();
thisObj.w.show();
}
else thisObj.w.layout.layout(true);
}
nsBatchParent.getThis = function(thisObj){
var activeComp = app.project.activeItem;
if(activeComp && activeComp instanceof CompItem){
if(activeComp.selectedLayers.length){
thisObj.thisBatch = activeComp.selectedLayers;
}
else alert("Select at least one layer")
}
}
nsBatchParent.getThat = function(thisObj){
var activeComp = app.project.activeItem;
if(activeComp && activeComp instanceof CompItem){
if(activeComp.selectedLayers && activeComp.selectedLayers.length === thisObj.thisBatch.length){
thisObj.thatBatch = activeComp.selectedLayers;
thisObj.parentShit(thisObj);
}
else alert("Select the same amount of layers: " + thisObj.thatBatch.length)
}
}
nsBatchParent.parentShit = function(thisObj){
app.beginUndoGroup("Batch Parenting");
for(var i = 0; i < thisObj.thisBatch.length; i++){
if(thisObj.thisBatch[i]!=thisObj.thatBatch[i]){
thisObj.thisBatch[i].parent = thisObj.thatBatch[i];
}
}
app.endUndoGroup();
}
nsBatchParent.run();