Skip to content

Commit b1d0d0d

Browse files
committed
Update gulp
1 parent 30e4de8 commit b1d0d0d

File tree

3 files changed

+235
-1
lines changed

3 files changed

+235
-1
lines changed

dist/explode_shape_layer.jsx

Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
function explodeLayer(layers) {
2+
3+
consLog('==============\n==============');
4+
5+
// Check if multiple layers selected
6+
if(layers.length > 1) {
7+
alert("Select a single shape layer");
8+
return;
9+
}
10+
11+
// Get the selected layer
12+
var layer = layers[0];
13+
14+
// Check if the layer is null or wrong type
15+
if(layer == undefined || layer.matchName !== 'ADBE Vector Layer') {
16+
alert("Select a shape layer");
17+
return;
18+
}
19+
20+
var comp = layer.containingComp;
21+
22+
// Get the elements of the original shape layer
23+
var contents = layer.property("Contents");
24+
var n_layers = [];
25+
26+
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 ?'))
27+
return;
28+
29+
30+
// Browse through contents array
31+
for(var i = contents.numProperties; i > 0; i--) {
32+
33+
// Get the original property
34+
var o_prop = contents.property(i);
35+
36+
// Skip the property if not enabled
37+
if (o_prop.enabled) {
38+
39+
// Duplicate the original layer and rename with property name
40+
var n_layer = comp.layers.addShape();
41+
n_layer.name = o_prop.name;
42+
n_layer.enabled = false;
43+
44+
n_layers.push(n_layer);
45+
46+
copyLayerTransform(layer, n_layer);
47+
48+
// Get the elements of the new layer
49+
var n_layerContents = n_layer.property("Contents");
50+
51+
insertPropertyToContents(o_prop, n_layerContents, '')
52+
53+
}
54+
55+
}
56+
57+
for(var i = 0; i < n_layers.length; i++) {
58+
n_layers[i].enabled = true;
59+
}
60+
61+
}
62+
63+
function insertPropertyToContents(prop, contents, prefix) {
64+
65+
if (!contents.canAddProperty(prop.matchName))
66+
return false;
67+
68+
var n_prop = contents.addProperty(prop.matchName)
69+
70+
for(var i=1; i <= prop.numProperties; i++) {
71+
72+
var innerProp = prop.property(i);
73+
74+
if(innerProp.enabled && n_prop.canAddProperty(innerProp.matchName)) {
75+
76+
consLog(prefix + innerProp.matchName);
77+
78+
var p = n_prop.property(innerProp.matchName) ? n_prop.property(innerProp.matchName) : n_prop.addProperty(innerProp.matchName);
79+
80+
switch (innerProp.matchName) {
81+
82+
case 'ADBE Vector Filter - Merge':
83+
copyProperty('mode', innerProp, p)
84+
break;
85+
86+
case 'ADBE Vector Materials Group':
87+
consLog(prefix + '-- skipped');
88+
break;
89+
90+
case 'ADBE Vector Graphic - Stroke':
91+
copyPropertyStroke(innerProp, p);
92+
break;
93+
94+
case 'ADBE Vector Graphic - Fill':
95+
copyPropertyFill(innerProp, p);
96+
break;
97+
98+
case 'ADBE Vector Transform Group':
99+
copyPropertyTransform(innerProp, p);
100+
break;
101+
102+
case 'ADBE Root Vectors Group':
103+
case 'ADBE Vectors Group':
104+
case 'ADBE Vector Group':
105+
insertPropertyToContents(innerProp, n_prop, prefix += ' ')
106+
break;
107+
108+
case 'ADBE Vector Shape - Group':
109+
copyPropertyShape(innerProp, p);
110+
break;
111+
112+
default:
113+
p.setValue( innerProp.value );
114+
115+
116+
117+
}
118+
119+
}
120+
121+
}
122+
123+
124+
}
125+
126+
function copyProperty(name, origin, target) {
127+
target[name].setValue( origin[name].value );
128+
}
129+
130+
function copyPropertyShape(origin, target) {
131+
target.property('ADBE Vector Shape').setValue( origin.property('ADBE Vector Shape').value );
132+
}
133+
134+
function copyPropertyStroke(origin, target) {
135+
136+
copyProperty('composite', origin, target);
137+
copyProperty('color', origin, target);
138+
copyProperty('strokeWidth', origin, target);
139+
copyProperty('lineCap', origin, target);
140+
copyProperty('lineJoin', origin, target);
141+
copyProperty('miterLimit', origin, target);
142+
143+
// TOFIX : dash are present, no mater if deleted or not ! (disabled for now)
144+
if(false && origin.dash.enabled) {
145+
146+
for(var i=1; i <= origin.dash.numProperties; i++) {
147+
148+
var dashProp = origin.dash.property(i);
149+
150+
if(dashProp.enabled)
151+
target.dash.addProperty(dashProp.matchName).setValue(dashProp.value);
152+
153+
}
154+
155+
}
156+
157+
}
158+
159+
function copyPropertyFill(origin, target) {
160+
161+
copyProperty('composite', origin, target);
162+
copyProperty('fillRule', origin, target);
163+
copyProperty('color', origin, target);
164+
165+
}
166+
167+
function copyPropertyTransform(origin, target) {
168+
169+
copyProperty('anchorPoint', origin, target);
170+
copyProperty('position', origin, target);
171+
copyProperty('scale', origin, target);
172+
copyProperty('skew', origin, target);
173+
copyProperty('skewAxis', origin, target);
174+
copyProperty('rotation', origin, target);
175+
copyProperty('opacity', origin, target);
176+
177+
}
178+
179+
function copyLayerTransform(origin, target) {
180+
181+
copyProperty('anchorPoint', origin, target);
182+
copyProperty('position', origin, target);
183+
copyProperty('scale', origin, target);
184+
copyProperty('rotation', origin, target);
185+
copyProperty('opacity', origin, target);
186+
187+
}
188+
189+
function createUI(thisObj) {
190+
191+
if(thisObj instanceof Panel) {
192+
193+
var myPanel = thisObj;
194+
195+
} else {
196+
197+
var myPanel = new Window('palette', configs.title, undefined, {
198+
resizeable : true,
199+
});
200+
myPanel.show();
201+
202+
}
203+
204+
var btn = myPanel.add("button", [10, 10, 100, 30], "Explode layer");
205+
206+
myPanel.text = configs.title;
207+
myPanel.bounds.width = 120;
208+
myPanel.bounds.height = 40;
209+
210+
btn.onClick = function() {
211+
212+
var t_start = new Date().getTime();
213+
214+
explodeLayer( app.project.activeItem.selectedLayers );
215+
216+
var t_end = new Date().getTime();
217+
consLog('Execution time : ' + (t_end - t_start) + 'ms');
218+
219+
}
220+
221+
return myPanel;
222+
223+
}
224+
225+
function consLog(text) { if (configs.log) $.writeln(text); }
226+
227+
var configs = {
228+
title: 'Explode layer tool',
229+
log : false,
230+
itemAmountWarning : 50,
231+
};
232+
233+
var myToolsPanel = 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 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)for(var r=o.containingComp,t=o.property("Contents"),p=1;p<=t.numProperties;p++){var a=t.property(p);if(a.enabled){var c=r.layers.addShape();c.name=a.name,copyLayerTransform(o,c),insertPropertyToContents(a,c.property("Contents"),"")}}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 a=e.property(p);if(a.enabled&&t.canAddProperty(a.matchName)){consLog(r+a.matchName);var c=t.property(a.matchName)?t.property(a.matchName):t.addProperty(a.matchName);switch(a.matchName){case"ADBE Vector Filter - Merge":case"ADBE Vector Materials Group":consLog(r+"-- skipped");break;case"ADBE Vector Graphic - Stroke":copyPropertyStroke(a,c);break;case"ADBE Vector Graphic - Fill":copyPropertyFill(a,c);break;case"ADBE Vector Transform Group":copyPropertyTransform(a,c);break;case"ADBE Root Vectors Group":case"ADBE Vectors Group":case"ADBE Vector Group":insertPropertyToContents(a,t,r+=" ");break;case"ADBE Vector Shape - Group":copyPropertyShape(a,c);break;default:c.setValue(a.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 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(){explodeLayer(app.project.activeItem.selectedLayers)},o}function consLog(e){configs.log&&$.writeln(e)}var configs={title:"Explode layer tool",log:!1},myToolsPanel=createUI(this);
1+
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"),a=[];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 p=t.property(n);if(p.enabled){var c=r.layers.addShape();c.name=p.name,c.enabled=!1,a.push(c),copyLayerTransform(o,c),insertPropertyToContents(p,c.property("Contents"),"")}}for(var n=0;n<a.length;n++)a[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),a=1;a<=e.numProperties;a++){var p=e.property(a);if(p.enabled&&t.canAddProperty(p.matchName)){consLog(r+p.matchName);var c=t.property(p.matchName)?t.property(p.matchName):t.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 Root Vectors Group":case"ADBE Vectors Group":case"ADBE Vector Group":insertPropertyToContents(p,t,r+=" ");break;case"ADBE Vector Shape - Group":copyPropertyShape(p,c);break;default: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 copyLayerTransform(e,o){copyProperty("anchorPoint",e,o),copyProperty("position",e,o),copyProperty("scale",e,o),copyProperty("rotation",e,o),copyProperty("opacity",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}function consLog(e){configs.log&&$.writeln(e)}var configs={title:"Explode layer tool",log:!1,itemAmountWarning:50},myToolsPanel=createUI(this);

gulpfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var uglify = require('gulp-uglify');
55
gulp.task('prod', function () {
66

77
gulp.src('src/explode_shape_layer.jsx')
8+
.pipe(gulp.dest('dist/'))
89
.pipe(rename('./explode_shape_layer.min.jsx'))
910
.pipe(uglify())
1011
.pipe(gulp.dest('dist/'))

0 commit comments

Comments
 (0)