Skip to content

Commit 45d5e03

Browse files
committed
Support for Rect, Ellipse and Star
1 parent a7452e6 commit 45d5e03

3 files changed

Lines changed: 95 additions & 5 deletions

File tree

dist/explode_shape_layer.jsx

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
function consLog(text) {
2+
if (configs.log)
3+
$.writeln(text);
4+
}
5+
6+
function listMatchNames(object) {
7+
consLog("LISTING ?")
8+
for(var i=1; i <= object.numProperties; i++) {
9+
10+
var prop = object.property(i);
11+
consLog(prop.matchName + '('+ prop.name +')');
12+
13+
}
14+
15+
}
16+
17+
/* @requires utils.jsx */
18+
119
function explodeLayer(layers) {
220

321
consLog('==============\n==============');
@@ -99,6 +117,18 @@ function insertPropertyToContents(prop, contents, prefix) {
99117
copyPropertyTransform(innerProp, p);
100118
break;
101119

120+
case 'ADBE Vector Shape - Rect':
121+
copyPropertyRect(innerProp, p);
122+
break;
123+
124+
case 'ADBE Vector Shape - Ellipse':
125+
copyPropertyEllipse(innerProp, p);
126+
break;
127+
128+
case 'ADBE Vector Shape - Star':
129+
copyPropertyStar(innerProp, p);
130+
break;
131+
102132
case 'ADBE Root Vectors Group':
103133
case 'ADBE Vectors Group':
104134
case 'ADBE Vector Group':
@@ -186,6 +216,31 @@ function copyLayerTransform(origin, target) {
186216

187217
}
188218

219+
function copyPropertyRect(origin, target) {
220+
copyProperty('shapeDirection', origin, target)
221+
copyProperty('size', origin, target)
222+
copyProperty('position', origin, target)
223+
copyProperty('roundness', origin, target)
224+
}
225+
226+
function copyPropertyEllipse(origin, target) {
227+
copyProperty('shapeDirection', origin, target)
228+
copyProperty('size', origin, target)
229+
copyProperty('position', origin, target)
230+
}
231+
232+
function copyPropertyStar(origin, target) {
233+
copyProperty('shapeDirection', origin, target)
234+
copyProperty('type', origin, target)
235+
copyProperty('points', origin, target)
236+
copyProperty('position', origin, target)
237+
copyProperty('rotation', origin, target)
238+
copyProperty('innerRadius', origin, target)
239+
copyProperty('outerRadius', origin, target)
240+
copyProperty('innerRoundness', origin, target)
241+
copyProperty('outerRoundness', origin, target)
242+
}
243+
189244
function createUI(thisObj) {
190245

191246
if(thisObj instanceof Panel) {
@@ -222,11 +277,9 @@ function createUI(thisObj) {
222277

223278
}
224279

225-
function consLog(text) { if (configs.log) $.writeln(text); }
226-
227280
var configs = {
228281
title: 'Explode layer tool',
229-
log : false,
282+
log : true,
230283
itemAmountWarning : 50,
231284
};
232285

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){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);
1+
function consLog(e){configs.log&&$.writeln(e)}function listMatchNames(e){consLog("LISTING ?");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:!0,itemAmountWarning:50},myToolsPanel=createUI(this);

src/explode_shape_layer.jsx

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@ function insertPropertyToContents(prop, contents, prefix) {
101101
copyPropertyTransform(innerProp, p);
102102
break;
103103

104+
case 'ADBE Vector Shape - Rect':
105+
copyPropertyRect(innerProp, p);
106+
break;
107+
108+
case 'ADBE Vector Shape - Ellipse':
109+
copyPropertyEllipse(innerProp, p);
110+
break;
111+
112+
case 'ADBE Vector Shape - Star':
113+
copyPropertyStar(innerProp, p);
114+
break;
115+
104116
case 'ADBE Root Vectors Group':
105117
case 'ADBE Vectors Group':
106118
case 'ADBE Vector Group':
@@ -188,6 +200,31 @@ function copyLayerTransform(origin, target) {
188200

189201
}
190202

203+
function copyPropertyRect(origin, target) {
204+
copyProperty('shapeDirection', origin, target)
205+
copyProperty('size', origin, target)
206+
copyProperty('position', origin, target)
207+
copyProperty('roundness', origin, target)
208+
}
209+
210+
function copyPropertyEllipse(origin, target) {
211+
copyProperty('shapeDirection', origin, target)
212+
copyProperty('size', origin, target)
213+
copyProperty('position', origin, target)
214+
}
215+
216+
function copyPropertyStar(origin, target) {
217+
copyProperty('shapeDirection', origin, target)
218+
copyProperty('type', origin, target)
219+
copyProperty('points', origin, target)
220+
copyProperty('position', origin, target)
221+
copyProperty('rotation', origin, target)
222+
copyProperty('innerRadius', origin, target)
223+
copyProperty('outerRadius', origin, target)
224+
copyProperty('innerRoundness', origin, target)
225+
copyProperty('outerRoundness', origin, target)
226+
}
227+
191228
function createUI(thisObj) {
192229

193230
if(thisObj instanceof Panel) {
@@ -226,7 +263,7 @@ function createUI(thisObj) {
226263

227264
var configs = {
228265
title: 'Explode layer tool',
229-
log : false,
266+
log : true,
230267
itemAmountWarning : 50,
231268
};
232269

0 commit comments

Comments
 (0)