-
Notifications
You must be signed in to change notification settings - Fork 0
/
ab-keepStrokeWidth.jsx
70 lines (53 loc) · 3.06 KB
/
ab-keepStrokeWidth.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
/***************************************************************************
* Keep stroke width *******************************************************
* by Arne Breusing @dezignphreak ******************************************
* version: 0.2 ************************************************************
***************************************************************************/
keepStrokeWidth(this);
/* apply the maintain stroke width expression to all strokes of the selected shape layers on the first level and ask for a new stroke width
*/
function keepStrokeWidth(thisObj) {
var myExpression = "// Maintain stroke width\nvalue / length(toComp([0,0]), toComp([0.7071,0.7071])) || 0.001;"
var myComp = app.project.activeItem;
if (myComp && myComp instanceof CompItem) {
var mySelection = myComp.selectedLayers;
var myNumLayers = mySelection.length;
var myLayernames = [];
var newStrokeWidth;
app.beginUndoGroup("Keep stroke width")
if (mySelection.length > 0) { // check if you have a layer selected
var newStrokeWidth = prompt('Adjusted stroke width? Leave blank for default', '') // prompt for new stroke width
for (var i = 0; i < mySelection.length; i++) {
if (mySelection[i] instanceof ShapeLayer) { // check if layer is shape layer
var myContents = mySelection[i].property('ADBE Root Vectors Group');
for (var j = 1; j <= myContents.numProperties; j++) { // loop through first level of subgroups of the shape layer
if (myContents.property(j).matchName == 'ADBE Vector Group') { // check if property is group
if (myContents.property(j).property('ADBE Vectors Group').property('ADBE Vector Graphic - Stroke') != null) {
var myStrokeWidth = myContents.property(j).property('ADBE Vectors Group').property('ADBE Vector Graphic - Stroke').property('ADBE Vector Stroke Width');
if (newStrokeWidth == null || newStrokeWidth == '' || newStrokeWidth == ' ' || newStrokeWidth == undefined) { // set stroke width to new stroke width if user has put in a new value
myStrokeWidth.setValue(myStrokeWidth.value);
} else {
myStrokeWidth.setValue(newStrokeWidth);
}
myStrokeWidth.expression = myExpression;
}
} else if (myContents.property(j).property('ADBE Vector Stroke Width') != null) {
var myStrokeWidth = myContents.property(j).property('ADBE Vector Stroke Width');
if (newStrokeWidth != null) { // set stroke width to new stroke width if user has put in a new value
myStrokeWidth.setValue(newStrokeWidth);
}
myStrokeWidth.expression = myExpression;
}
}
}
myLayernames.push(mySelection[i].name);
}
//alert("The stroke of the following layers has been adjusted:\n\n" + myLayernames.join("\n"));
} else {
alert("Please select a layer first first.");
}
app.endUndoGroup();
} else {
alert("Please select a composition first.");
}
};