Skip to content

Commit 9e065ef

Browse files
committed
Add progress bar
1 parent 0b7a958 commit 9e065ef

4 files changed

Lines changed: 104 additions & 3 deletions

File tree

dist/explode_shape_layer.jsx

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,53 @@ function listMatchNames(object) {
2020

2121
}
2222

23-
/* @requires utils.jsx */
23+
_progressBar = new Window('palette', configs.title, undefined, {
24+
resizeable : false,
25+
borderless : 'not quite true',
26+
});
27+
28+
_progressBar.preferredSize = [420, 40];
29+
_progressBar.bar = _progressBar.add("progressbar", undefined, 0, 100);
30+
_progressBar.bar.value = 0;
31+
_progressBar.bar.preferredSize.width = 400;
32+
_progressBar.bar.show()
33+
34+
_progressBar.barInfos = _progressBar.add("statictext", undefined, 'Loading, please wait', {
35+
justify: 'center'
36+
});
37+
_progressBar.barInfos.preferredSize = [400, 17];
38+
39+
_progressBar.make = function (min, max, current) {
40+
this.barProps = {
41+
min : min,
42+
max : max,
43+
current : current,
44+
}
45+
this.barProps.total = (this.barProps.max - this.barProps.min) + 1;
46+
this.barProps.step = (this.barProps.current - this.barProps.min) + 1;
47+
}
48+
49+
_progressBar.updateBar = function () {
50+
this.bar.value = Math.round(( (this.barProps.step) * 100) / this.barProps.max)
51+
consLog('Processing element ' + (this.barProps.step + 1) + ' on ' + this.barProps.total);
52+
this.barInfos.text = 'Processing element ' + (this.barProps.step + 1) + ' on ' + this.barProps.total;
53+
}
54+
55+
_progressBar.showBar = function () { this.show(); }
56+
57+
_progressBar.hideBar = function () { this.hide(); }
58+
59+
_progressBar.setCurrent = function (current, text) {
60+
this.barProps.current = current;
61+
this.barProps.step = (this.barProps.current - this.barProps.min) + 1;
62+
this.updateBar();
63+
this.update();
64+
}
65+
66+
/*
67+
* @requires utils.jsx
68+
* @requires progressBar.jsx
69+
*/
2470

2571
function explodeLayer(layer) {
2672

@@ -41,12 +87,15 @@ function explodeLayer(layer) {
4187

4288
}
4389

90+
_progressBar.make(1, contents.numProperties, 1);
91+
_progressBar.showBar();
4492

4593
// Browse through contents array
4694
for(var i = contents.numProperties; i > 0; i--) {
4795

4896
// Get the original property
4997
var _prop = contents.property(i);
98+
_progressBar.setCurrent(contents.numProperties - i)
5099

51100
// Skip the property if not enabled
52101
if (!_prop.enabled) continue;
@@ -67,6 +116,8 @@ function explodeLayer(layer) {
67116

68117
}
69118

119+
_progressBar.hideBar();
120+
70121
for(var i = 0; i < layers.length; i++) {
71122
layers[i].enabled = true;
72123
}

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){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);
1+
function consLog(r){configs.log&&$.writeln(r)}function listMatchNames(r){for(var e=1;e<=r.numProperties;e++){var o=r.property(e);consLog(o.matchName+"("+o.name+")")}}function explodeLayer(r){consLog("==============\n==============");var e=r.property("Contents"),o=[];if(!(e.numProperties>configs.itemAmountWarning)||confirm("You have more than "+configs.itemAmountWarning+" elements. Execution time might be long, are you sure you want to continue ?")){_progressBar.make(1,e.numProperties,1),_progressBar.showBar();for(a=e.numProperties;a>0;a--){var t=e.property(a);if(_progressBar.setCurrent(e.numProperties-a),t.enabled){var p=emptyDuplicateLayer(r);p.name=r.name+" - "+t.name,p.enabled=!1,o.push(p),p.property("Contents").canAddProperty(t.matchName)&&copyProperties(t,p.property("Contents").addProperty(t.matchName),"")}}_progressBar.hideBar();for(var a=0;a<o.length;a++)o[a].enabled=!0}}function explode(){if(app.project.activeItem.selectedLayers.length>1)alert("Select a single shape layer");else{var r=app.project.activeItem.selectedLayers[0];void 0!=r&&"ADBE Vector Layer"===r.matchName?explodeLayer(r):alert("Select a shape layer")}}function emptyDuplicateLayer(r){var e=r.containingComp.layers.addShape();return copyProperty("anchorPoint",r,e),copyProperty("position",r,e),copyProperty("scale",r,e),copyProperty("rotation",r,e),copyProperty("opacity",r,e),e}function copyProperties(r,e,o){for(var t=1;t<=r.numProperties;t++){var p=r.property(t);if(!p.enabled||!e.canAddProperty(p.matchName))return;consLog(o+p.matchName);var a=e.addProperty(p.matchName);switch(p.matchName){case"ADBE Vector Filter - Merge":copyProperty("mode",p,a);break;case"ADBE Vector Materials Group":consLog(o+"-- skipped");break;case"ADBE Vector Graphic - Stroke":copyPropertyStroke(p,a);break;case"ADBE Vector Graphic - Fill":copyPropertyFill(p,a);break;case"ADBE Vector Transform Group":copyPropertyTransform(p,a);break;case"ADBE Vector Shape - Rect":copyPropertyRect(p,a);break;case"ADBE Vector Shape - Ellipse":copyPropertyEllipse(p,a);break;case"ADBE Vector Shape - Star":copyPropertyStar(p,a);break;case"ADBE Root Vectors Group":case"ADBE Vectors Group":case"ADBE Vector Group":copyProperties(p,a,o+=" ");break;case"ADBE Vector Shape - Group":copyPropertyShape(p,a);break;case"ADBE Vector Blend Mode":a.setValue(p.value)}}}function copyProperty(r,e,o){o[r].setValue(e[r].value)}function copyPropertyShape(r,e){e.property("ADBE Vector Shape").setValue(r.property("ADBE Vector Shape").value)}function copyPropertyStroke(r,e){copyProperty("composite",r,e),copyProperty("color",r,e),copyProperty("strokeWidth",r,e),copyProperty("lineCap",r,e),copyProperty("lineJoin",r,e),copyProperty("miterLimit",r,e)}function copyPropertyFill(r,e){copyProperty("composite",r,e),copyProperty("fillRule",r,e),copyProperty("color",r,e)}function copyPropertyTransform(r,e){copyProperty("anchorPoint",r,e),copyProperty("position",r,e),copyProperty("scale",r,e),copyProperty("skew",r,e),copyProperty("skewAxis",r,e),copyProperty("rotation",r,e),copyProperty("opacity",r,e)}function copyPropertyRect(r,e){copyProperty("shapeDirection",r,e),copyProperty("size",r,e),copyProperty("position",r,e),copyProperty("roundness",r,e)}function copyPropertyEllipse(r,e){copyProperty("shapeDirection",r,e),copyProperty("size",r,e),copyProperty("position",r,e)}function copyPropertyStar(r,e){copyProperty("shapeDirection",r,e),copyProperty("type",r,e),copyProperty("points",r,e),copyProperty("position",r,e),copyProperty("rotation",r,e),copyProperty("innerRadius",r,e),copyProperty("outerRadius",r,e),copyProperty("innerRoundness",r,e),copyProperty("outerRoundness",r,e)}function createUI(r){if(r instanceof Panel);else{var e=new Window("palette",configs.title,void 0,{resizeable:!0});e.show()}var o=e.add("button",[10,10,100,30],"Explode layer");return e.text=configs.title,e.bounds.width=120,e.bounds.height=40,o.onClick=function(){var r=(new Date).getTime();explode();var e=(new Date).getTime()-r;consLog("Execution time : "+Math.floor(e/1e3)+"s "+e%1e3+"ms")},e}var configs={title:"Explode layer tool",log:!0,itemAmountWarning:50};_progressBar=new Window("palette",configs.title,void 0,{resizeable:!1,borderless:"not quite true"}),_progressBar.preferredSize=[420,40],_progressBar.bar=_progressBar.add("progressbar",void 0,0,100),_progressBar.bar.value=0,_progressBar.bar.preferredSize.width=400,_progressBar.bar.show(),_progressBar.barInfos=_progressBar.add("statictext",void 0,"Loading, please wait",{justify:"center"}),_progressBar.barInfos.preferredSize=[400,17],_progressBar.make=function(r,e,o){this.barProps={min:r,max:e,current:o},this.barProps.total=this.barProps.max-this.barProps.min+1,this.barProps.step=this.barProps.current-this.barProps.min+1},_progressBar.updateBar=function(){this.bar.value=Math.round(100*this.barProps.step/this.barProps.max),consLog("Processing element "+(this.barProps.step+1)+" on "+this.barProps.total),this.barInfos.text="Processing element "+(this.barProps.step+1)+" on "+this.barProps.total},_progressBar.showBar=function(){this.show()},_progressBar.hideBar=function(){this.hide()},_progressBar.setCurrent=function(r,e){this.barProps.current=r,this.barProps.step=this.barProps.current-this.barProps.min+1,this.updateBar(),this.update()};var _panel=createUI(this);

src/explode_shape_layer.jsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
/* @requires utils.jsx */
1+
/*
2+
* @requires utils.jsx
3+
* @requires progressBar.jsx
4+
*/
25

36
function explodeLayer(layer) {
47

@@ -19,12 +22,15 @@ function explodeLayer(layer) {
1922

2023
}
2124

25+
_progressBar.make(1, contents.numProperties, 1);
26+
_progressBar.showBar();
2227

2328
// Browse through contents array
2429
for(var i = contents.numProperties; i > 0; i--) {
2530

2631
// Get the original property
2732
var _prop = contents.property(i);
33+
_progressBar.setCurrent(contents.numProperties - i)
2834

2935
// Skip the property if not enabled
3036
if (!_prop.enabled) continue;
@@ -45,6 +51,8 @@ function explodeLayer(layer) {
4551

4652
}
4753

54+
_progressBar.hideBar();
55+
4856
for(var i = 0; i < layers.length; i++) {
4957
layers[i].enabled = true;
5058
}

src/progressBar.jsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
_progressBar = new Window('palette', configs.title, undefined, {
2+
resizeable : false,
3+
borderless : 'not quite true',
4+
});
5+
6+
_progressBar.preferredSize = [420, 40];
7+
_progressBar.bar = _progressBar.add("progressbar", undefined, 0, 100);
8+
_progressBar.bar.value = 0;
9+
_progressBar.bar.preferredSize.width = 400;
10+
_progressBar.bar.show()
11+
12+
_progressBar.barInfos = _progressBar.add("statictext", undefined, 'Loading, please wait', {
13+
justify: 'center'
14+
});
15+
_progressBar.barInfos.preferredSize = [400, 17];
16+
17+
_progressBar.make = function (min, max, current) {
18+
this.barProps = {
19+
min : min,
20+
max : max,
21+
current : current,
22+
}
23+
this.barProps.total = (this.barProps.max - this.barProps.min) + 1;
24+
this.barProps.step = (this.barProps.current - this.barProps.min) + 1;
25+
}
26+
27+
_progressBar.updateBar = function () {
28+
this.bar.value = Math.round(( (this.barProps.step) * 100) / this.barProps.max)
29+
consLog('Processing element ' + (this.barProps.step + 1) + ' on ' + this.barProps.total);
30+
this.barInfos.text = 'Processing element ' + (this.barProps.step + 1) + ' on ' + this.barProps.total;
31+
}
32+
33+
_progressBar.showBar = function () { this.show(); }
34+
35+
_progressBar.hideBar = function () { this.hide(); }
36+
37+
_progressBar.setCurrent = function (current, text) {
38+
this.barProps.current = current;
39+
this.barProps.step = (this.barProps.current - this.barProps.min) + 1;
40+
this.updateBar();
41+
this.update();
42+
}

0 commit comments

Comments
 (0)