Skip to content

Commit 0b7a958

Browse files
committed
Human readable execution time log
1 parent aad45e9 commit 0b7a958

3 files changed

Lines changed: 128 additions & 123 deletions

File tree

dist/explode_shape_layer.jsx

Lines changed: 124 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var configs = {
22
title: 'Explode layer tool',
3-
log : false,
3+
log : true,
44
itemAmountWarning : 50,
55
};
66

@@ -10,7 +10,7 @@ function consLog(text) {
1010
}
1111

1212
function listMatchNames(object) {
13-
13+
1414
for(var i=1; i <= object.numProperties; i++) {
1515

1616
var prop = object.property(i);
@@ -22,141 +22,155 @@ function listMatchNames(object) {
2222

2323
/* @requires utils.jsx */
2424

25-
function explodeLayer(layers) {
25+
function explodeLayer(layer) {
2626

2727
consLog('==============\n==============');
2828

29-
// Check if multiple layers selected
30-
if(layers.length > 1) {
31-
alert("Select a single shape layer");
32-
return;
33-
}
34-
35-
// Get the selected layer
36-
var layer = layers[0];
29+
// Get the elements of the original shape layer
30+
var contents = layer.property("Contents");
31+
var layers = [];
3732

38-
// Check if the layer is null or wrong type
39-
if(layer == undefined || layer.matchName !== 'ADBE Vector Layer') {
40-
alert("Select a shape layer");
41-
return;
42-
}
33+
if(contents.numProperties > configs.itemAmountWarning) {
4334

44-
var comp = layer.containingComp;
35+
var go = confirm(
36+
'You have more than ' + configs.itemAmountWarning + ' elements. '
37+
+ 'Execution time might be long, are you sure you want to continue ?'
38+
);
4539

46-
// Get the elements of the original shape layer
47-
var contents = layer.property("Contents");
48-
var n_layers = [];
40+
if(!go) return;
4941

50-
if(contents.numProperties > configs.itemAmountWarning && !confirm('You have more than ' + configs.itemAmountWarning + ' elements. Execution time might be long, are you sure you want to continue ?'))
51-
return;
42+
}
5243

5344

5445
// Browse through contents array
5546
for(var i = contents.numProperties; i > 0; i--) {
5647

5748
// Get the original property
58-
var o_prop = contents.property(i);
49+
var _prop = contents.property(i);
5950

6051
// Skip the property if not enabled
61-
if (o_prop.enabled) {
52+
if (!_prop.enabled) continue;
6253

63-
// Duplicate the original layer and rename with property name
64-
var n_layer = comp.layers.addShape();
65-
n_layer.name = o_prop.name;
66-
n_layer.enabled = false;
54+
// Duplicate the original layer and rename with property name
55+
var new_layer = emptyDuplicateLayer(layer)
6756

68-
n_layers.push(n_layer);
57+
new_layer.name = layer.name + ' - ' + _prop.name;
58+
new_layer.enabled = false;
6959

70-
copyLayerTransform(layer, n_layer);
60+
layers.push(new_layer);
7161

72-
// Get the elements of the new layer
73-
var n_layerContents = n_layer.property("Contents");
62+
if (!new_layer.property("Contents").canAddProperty(_prop.matchName)) continue;
7463

75-
insertPropertyToContents(o_prop, n_layerContents, '')
64+
var prop = new_layer.property("Contents").addProperty(_prop.matchName)
7665

77-
}
66+
copyProperties(_prop, prop, '')
7867

7968
}
8069

81-
for(var i = 0; i < n_layers.length; i++) {
82-
n_layers[i].enabled = true;
70+
for(var i = 0; i < layers.length; i++) {
71+
layers[i].enabled = true;
8372
}
8473

8574
}
8675

87-
function insertPropertyToContents(prop, contents, prefix) {
76+
function explode() {
8877

89-
if (!contents.canAddProperty(prop.matchName))
90-
return false;
78+
// Check if multiple layers selected
79+
if(app.project.activeItem.selectedLayers.length > 1) {
80+
alert("Select a single shape layer");
81+
return;
82+
}
9183

92-
var n_prop = contents.addProperty(prop.matchName)
84+
var selectedLayer = app.project.activeItem.selectedLayers[0];
9385

94-
for(var i=1; i <= prop.numProperties; i++) {
86+
// Check if the layer is null or wrong type
87+
if(selectedLayer == undefined || selectedLayer.matchName !== 'ADBE Vector Layer') {
88+
alert("Select a shape layer");
89+
return;
90+
}
9591

96-
var innerProp = prop.property(i);
92+
explodeLayer(selectedLayer);
9793

98-
if(innerProp.enabled && n_prop.canAddProperty(innerProp.matchName)) {
94+
}
9995

100-
consLog(prefix + innerProp.matchName);
96+
function emptyDuplicateLayer(layer) {
10197

102-
var p = n_prop.property(innerProp.matchName) ? n_prop.property(innerProp.matchName) : n_prop.addProperty(innerProp.matchName);
98+
var new_layer = layer.containingComp.layers.addShape();
10399

104-
switch (innerProp.matchName) {
100+
copyProperty('anchorPoint', layer, new_layer);
101+
copyProperty('position', layer, new_layer);
102+
copyProperty('scale', layer, new_layer);
103+
copyProperty('rotation', layer, new_layer);
104+
copyProperty('opacity', layer, new_layer);
105105

106-
case 'ADBE Vector Filter - Merge':
107-
copyProperty('mode', innerProp, p)
108-
break;
106+
return new_layer;
109107

110-
case 'ADBE Vector Materials Group':
111-
consLog(prefix + '-- skipped');
112-
break;
108+
}
109+
110+
function copyProperties(origin, target, prefix) {
111+
112+
for(var i=1; i <= origin.numProperties; i++) {
113+
114+
var _prop = origin.property(i);
115+
116+
if(!_prop.enabled || !target.canAddProperty(_prop.matchName)) return;
117+
118+
consLog(prefix + _prop.matchName);
119+
120+
var prop = target.addProperty(_prop.matchName);
113121

114-
case 'ADBE Vector Graphic - Stroke':
115-
copyPropertyStroke(innerProp, p);
116-
break;
122+
switch (_prop.matchName) {
117123

118-
case 'ADBE Vector Graphic - Fill':
119-
copyPropertyFill(innerProp, p);
120-
break;
124+
case 'ADBE Vector Filter - Merge':
125+
copyProperty('mode', _prop, prop)
126+
break;
121127

122-
case 'ADBE Vector Transform Group':
123-
copyPropertyTransform(innerProp, p);
124-
break;
128+
case 'ADBE Vector Materials Group':
129+
consLog(prefix + '-- skipped');
130+
break;
125131

126-
case 'ADBE Vector Shape - Rect':
127-
copyPropertyRect(innerProp, p);
128-
break;
132+
case 'ADBE Vector Graphic - Stroke':
133+
copyPropertyStroke(_prop, prop);
134+
break;
129135

130-
case 'ADBE Vector Shape - Ellipse':
131-
copyPropertyEllipse(innerProp, p);
132-
break;
136+
case 'ADBE Vector Graphic - Fill':
137+
copyPropertyFill(_prop, prop);
138+
break;
133139

134-
case 'ADBE Vector Shape - Star':
135-
copyPropertyStar(innerProp, p);
136-
break;
140+
case 'ADBE Vector Transform Group':
141+
copyPropertyTransform(_prop, prop);
142+
break;
137143

138-
case 'ADBE Root Vectors Group':
139-
case 'ADBE Vectors Group':
140-
case 'ADBE Vector Group':
141-
insertPropertyToContents(innerProp, n_prop, prefix += ' ')
142-
break;
144+
case 'ADBE Vector Shape - Rect':
145+
copyPropertyRect(_prop, prop);
146+
break;
143147

144-
case 'ADBE Vector Shape - Group':
145-
copyPropertyShape(innerProp, p);
146-
break;
148+
case 'ADBE Vector Shape - Ellipse':
149+
copyPropertyEllipse(_prop, prop);
150+
break;
147151

148-
default:
149-
p.setValue( innerProp.value );
152+
case 'ADBE Vector Shape - Star':
153+
copyPropertyStar(_prop, prop);
154+
break;
150155

156+
case 'ADBE Root Vectors Group':
157+
case 'ADBE Vectors Group':
158+
case 'ADBE Vector Group':
159+
copyProperties(_prop, prop, prefix += ' ')
160+
break;
151161

162+
case 'ADBE Vector Shape - Group':
163+
copyPropertyShape(_prop, prop);
164+
break;
152165

153-
}
166+
case 'ADBE Vector Blend Mode':
167+
prop.setValue( _prop.value );
168+
break;
154169

155170
}
156171

157172
}
158173

159-
160174
}
161175

162176
function copyProperty(name, origin, target) {
@@ -177,18 +191,18 @@ function copyPropertyStroke(origin, target) {
177191
copyProperty('miterLimit', origin, target);
178192

179193
// TOFIX : dash are present, no mater if deleted or not ! (disabled for now)
180-
if(false && origin.dash.enabled) {
181-
182-
for(var i=1; i <= origin.dash.numProperties; i++) {
183-
184-
var dashProp = origin.dash.property(i);
185-
186-
if(dashProp.enabled)
187-
target.dash.addProperty(dashProp.matchName).setValue(dashProp.value);
188-
189-
}
190-
191-
}
194+
// if(false && origin.dash.enabled) {
195+
//
196+
// for(var i=1; i <= origin.dash.numProperties; i++) {
197+
//
198+
// var dashProp = origin.dash.property(i);
199+
//
200+
// if(dashProp.enabled)
201+
// target.dash.addProperty(dashProp.matchName).setValue(dashProp.value);
202+
//
203+
// }
204+
//
205+
// }
192206

193207
}
194208

@@ -212,16 +226,6 @@ function copyPropertyTransform(origin, target) {
212226

213227
}
214228

215-
function copyLayerTransform(origin, target) {
216-
217-
copyProperty('anchorPoint', origin, target);
218-
copyProperty('position', origin, target);
219-
copyProperty('scale', origin, target);
220-
copyProperty('rotation', origin, target);
221-
copyProperty('opacity', origin, target);
222-
223-
}
224-
225229
function copyPropertyRect(origin, target) {
226230
copyProperty('shapeDirection', origin, target)
227231
copyProperty('size', origin, target)
@@ -247,40 +251,41 @@ function copyPropertyStar(origin, target) {
247251
copyProperty('outerRoundness', origin, target)
248252
}
249253

250-
function createUI(thisObj) {
254+
function createUI(that) {
251255

252-
if(thisObj instanceof Panel) {
256+
if(that instanceof Panel) {
253257

254-
var myPanel = thisObj;
258+
var myPanel = that;
255259

256260
} else {
257261

258-
var myPanel = new Window('palette', configs.title, undefined, {
262+
var _panel = new Window('palette', configs.title, undefined, {
259263
resizeable : true,
260264
});
261-
myPanel.show();
265+
_panel.show();
262266

263267
}
264268

265-
var btn = myPanel.add("button", [10, 10, 100, 30], "Explode layer");
269+
var btn = _panel.add("button", [10, 10, 100, 30], "Explode layer");
266270

267-
myPanel.text = configs.title;
268-
myPanel.bounds.width = 120;
269-
myPanel.bounds.height = 40;
271+
_panel.text = configs.title;
272+
_panel.bounds.width = 120;
273+
_panel.bounds.height = 40;
270274

271275
btn.onClick = function() {
272276

273-
var t_start = new Date().getTime();
277+
var startTime = new Date().getTime();
278+
279+
explode();
274280

275-
explodeLayer( app.project.activeItem.selectedLayers );
281+
var execTime = new Date().getTime() - startTime;
276282

277-
var t_end = new Date().getTime();
278-
consLog('Execution time : ' + (t_end - t_start) + 'ms');
283+
consLog('Execution time : ' + Math.floor(execTime / 1000) + 's ' + (execTime % 1000) + 'ms');
279284

280285
}
281286

282-
return myPanel;
287+
return _panel;
283288

284289
}
285290

286-
var myToolsPanel = createUI(this);
291+
var _panel = createUI(this);

dist/explode_shape_layer.min.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
function consLog(e){configs.log&&$.writeln(e)}function listMatchNames(e){for(var o=1;o<=e.numProperties;o++){var r=e.property(o);consLog(r.matchName+"("+r.name+")")}}function explodeLayer(e){if(consLog("==============\n=============="),e.length>1)alert("Select a single shape layer");else{var o=e[0];if(void 0!=o&&"ADBE Vector Layer"===o.matchName){var r=o.containingComp,t=o.property("Contents"),p=[];if(!(t.numProperties>configs.itemAmountWarning)||confirm("You have more than "+configs.itemAmountWarning+" elements. Execution time might be long, are you sure you want to continue ?")){for(n=t.numProperties;n>0;n--){var c=t.property(n);if(c.enabled){var a=r.layers.addShape();a.name=c.name,a.enabled=!1,p.push(a),copyLayerTransform(o,a),insertPropertyToContents(c,a.property("Contents"),"")}}for(var n=0;n<p.length;n++)p[n].enabled=!0}}else alert("Select a shape layer")}}function insertPropertyToContents(e,o,r){if(!o.canAddProperty(e.matchName))return!1;for(var t=o.addProperty(e.matchName),p=1;p<=e.numProperties;p++){var c=e.property(p);if(c.enabled&&t.canAddProperty(c.matchName)){consLog(r+c.matchName);var a=t.property(c.matchName)?t.property(c.matchName):t.addProperty(c.matchName);switch(c.matchName){case"ADBE Vector Filter - Merge":copyProperty("mode",c,a);break;case"ADBE Vector Materials Group":consLog(r+"-- skipped");break;case"ADBE Vector Graphic - Stroke":copyPropertyStroke(c,a);break;case"ADBE Vector Graphic - Fill":copyPropertyFill(c,a);break;case"ADBE Vector Transform Group":copyPropertyTransform(c,a);break;case"ADBE Vector Shape - Rect":copyPropertyRect(c,a);break;case"ADBE Vector Shape - Ellipse":copyPropertyEllipse(c,a);break;case"ADBE Vector Shape - Star":copyPropertyStar(c,a);break;case"ADBE Root Vectors Group":case"ADBE Vectors Group":case"ADBE Vector Group":insertPropertyToContents(c,t,r+=" ");break;case"ADBE Vector Shape - Group":copyPropertyShape(c,a);break;default:a.setValue(c.value)}}}}function copyProperty(e,o,r){r[e].setValue(o[e].value)}function copyPropertyShape(e,o){o.property("ADBE Vector Shape").setValue(e.property("ADBE Vector Shape").value)}function copyPropertyStroke(e,o){copyProperty("composite",e,o),copyProperty("color",e,o),copyProperty("strokeWidth",e,o),copyProperty("lineCap",e,o),copyProperty("lineJoin",e,o),copyProperty("miterLimit",e,o)}function copyPropertyFill(e,o){copyProperty("composite",e,o),copyProperty("fillRule",e,o),copyProperty("color",e,o)}function copyPropertyTransform(e,o){copyProperty("anchorPoint",e,o),copyProperty("position",e,o),copyProperty("scale",e,o),copyProperty("skew",e,o),copyProperty("skewAxis",e,o),copyProperty("rotation",e,o),copyProperty("opacity",e,o)}function copyLayerTransform(e,o){copyProperty("anchorPoint",e,o),copyProperty("position",e,o),copyProperty("scale",e,o),copyProperty("rotation",e,o),copyProperty("opacity",e,o)}function copyPropertyRect(e,o){copyProperty("shapeDirection",e,o),copyProperty("size",e,o),copyProperty("position",e,o),copyProperty("roundness",e,o)}function copyPropertyEllipse(e,o){copyProperty("shapeDirection",e,o),copyProperty("size",e,o),copyProperty("position",e,o)}function copyPropertyStar(e,o){copyProperty("shapeDirection",e,o),copyProperty("type",e,o),copyProperty("points",e,o),copyProperty("position",e,o),copyProperty("rotation",e,o),copyProperty("innerRadius",e,o),copyProperty("outerRadius",e,o),copyProperty("innerRoundness",e,o),copyProperty("outerRoundness",e,o)}function createUI(e){if(e instanceof Panel)var o=e;else(o=new Window("palette",configs.title,void 0,{resizeable:!0})).show();var r=o.add("button",[10,10,100,30],"Explode layer");return o.text=configs.title,o.bounds.width=120,o.bounds.height=40,r.onClick=function(){var e=(new Date).getTime();explodeLayer(app.project.activeItem.selectedLayers),consLog("Execution time : "+((new Date).getTime()-e)+"ms")},o}var configs={title:"Explode layer tool",log:!1,itemAmountWarning:50},myToolsPanel=createUI(this);
1+
function consLog(e){configs.log&&$.writeln(e)}function listMatchNames(e){for(var o=1;o<=e.numProperties;o++){var r=e.property(o);consLog(r.matchName+"("+r.name+")")}}function explodeLayer(e){consLog("==============\n==============");var o=e.property("Contents"),r=[];if(!(o.numProperties>configs.itemAmountWarning)||confirm("You have more than "+configs.itemAmountWarning+" elements. Execution time might be long, are you sure you want to continue ?")){for(c=o.numProperties;c>0;c--){var t=o.property(c);if(t.enabled){var p=emptyDuplicateLayer(e);p.name=e.name+" - "+t.name,p.enabled=!1,r.push(p),p.property("Contents").canAddProperty(t.matchName)&&copyProperties(t,p.property("Contents").addProperty(t.matchName),"")}}for(var c=0;c<r.length;c++)r[c].enabled=!0}}function explode(){if(app.project.activeItem.selectedLayers.length>1)alert("Select a single shape layer");else{var e=app.project.activeItem.selectedLayers[0];void 0!=e&&"ADBE Vector Layer"===e.matchName?explodeLayer(e):alert("Select a shape layer")}}function emptyDuplicateLayer(e){var o=e.containingComp.layers.addShape();return copyProperty("anchorPoint",e,o),copyProperty("position",e,o),copyProperty("scale",e,o),copyProperty("rotation",e,o),copyProperty("opacity",e,o),o}function copyProperties(e,o,r){for(var t=1;t<=e.numProperties;t++){var p=e.property(t);if(!p.enabled||!o.canAddProperty(p.matchName))return;consLog(r+p.matchName);var c=o.addProperty(p.matchName);switch(p.matchName){case"ADBE Vector Filter - Merge":copyProperty("mode",p,c);break;case"ADBE Vector Materials Group":consLog(r+"-- skipped");break;case"ADBE Vector Graphic - Stroke":copyPropertyStroke(p,c);break;case"ADBE Vector Graphic - Fill":copyPropertyFill(p,c);break;case"ADBE Vector Transform Group":copyPropertyTransform(p,c);break;case"ADBE Vector Shape - Rect":copyPropertyRect(p,c);break;case"ADBE Vector Shape - Ellipse":copyPropertyEllipse(p,c);break;case"ADBE Vector Shape - Star":copyPropertyStar(p,c);break;case"ADBE Root Vectors Group":case"ADBE Vectors Group":case"ADBE Vector Group":copyProperties(p,c,r+=" ");break;case"ADBE Vector Shape - Group":copyPropertyShape(p,c);break;case"ADBE Vector Blend Mode":c.setValue(p.value)}}}function copyProperty(e,o,r){r[e].setValue(o[e].value)}function copyPropertyShape(e,o){o.property("ADBE Vector Shape").setValue(e.property("ADBE Vector Shape").value)}function copyPropertyStroke(e,o){copyProperty("composite",e,o),copyProperty("color",e,o),copyProperty("strokeWidth",e,o),copyProperty("lineCap",e,o),copyProperty("lineJoin",e,o),copyProperty("miterLimit",e,o)}function copyPropertyFill(e,o){copyProperty("composite",e,o),copyProperty("fillRule",e,o),copyProperty("color",e,o)}function copyPropertyTransform(e,o){copyProperty("anchorPoint",e,o),copyProperty("position",e,o),copyProperty("scale",e,o),copyProperty("skew",e,o),copyProperty("skewAxis",e,o),copyProperty("rotation",e,o),copyProperty("opacity",e,o)}function copyPropertyRect(e,o){copyProperty("shapeDirection",e,o),copyProperty("size",e,o),copyProperty("position",e,o),copyProperty("roundness",e,o)}function copyPropertyEllipse(e,o){copyProperty("shapeDirection",e,o),copyProperty("size",e,o),copyProperty("position",e,o)}function copyPropertyStar(e,o){copyProperty("shapeDirection",e,o),copyProperty("type",e,o),copyProperty("points",e,o),copyProperty("position",e,o),copyProperty("rotation",e,o),copyProperty("innerRadius",e,o),copyProperty("outerRadius",e,o),copyProperty("innerRoundness",e,o),copyProperty("outerRoundness",e,o)}function createUI(e){if(e instanceof Panel);else{var o=new Window("palette",configs.title,void 0,{resizeable:!0});o.show()}var r=o.add("button",[10,10,100,30],"Explode layer");return o.text=configs.title,o.bounds.width=120,o.bounds.height=40,r.onClick=function(){var e=(new Date).getTime();explode();var o=(new Date).getTime()-e;consLog("Execution time : "+Math.floor(o/1e3)+"s "+o%1e3+"ms")},o}var configs={title:"Explode layer tool",log:!0,itemAmountWarning:50},_panel=createUI(this);

src/explode_shape_layer.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,13 @@ function createUI(that) {
252252

253253
btn.onClick = function() {
254254

255-
var t_start = new Date().getTime();
255+
var startTime = new Date().getTime();
256256

257257
explode();
258258

259+
var execTime = new Date().getTime() - startTime;
259260

260-
var t_end = new Date().getTime();
261-
consLog('Execution time : ' + (t_end - t_start) + 'ms');
261+
consLog('Execution time : ' + Math.floor(execTime / 1000) + 's ' + (execTime % 1000) + 'ms');
262262

263263
}
264264

0 commit comments

Comments
 (0)