Skip to content

Commit 665b78d

Browse files
committed
Refactor to a more efficient process
1 parent adcf39b commit 665b78d

File tree

2 files changed

+158
-11
lines changed

2 files changed

+158
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Select the Shape Layer you want to explode, launch the script... tadaaa !
1010

1111

1212
## Installation
13-
Copy the `.jsx` file to the After Effets' default script folder or/then launch the script directly from After Effects panel : `File > Scripts > ...`
13+
Copy the `.jsx` file into your After Effets' "ScriptUI" folder.
1414

1515
## Compatibility
1616
Works on :

explode_shape_layer.jsx

Lines changed: 157 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
function explodeLayer(layers) {
1+
function explodeLayer(layers) {
2+
3+
consLog('==============\n==============');
24

35
// Check if multiple layers selected
46
if(layers.length > 1) {
@@ -15,6 +17,8 @@ function explodeLayer(layers) {
1517
return;
1618
}
1719

20+
var comp = layer.containingComp;
21+
1822
// Get the elements of the original shape layer
1923
var contents = layer.property("Contents");
2024

@@ -28,29 +32,172 @@ function explodeLayer(layers) {
2832
if (o_prop.enabled) {
2933

3034
// Duplicate the original layer and rename with property name
31-
var n_layer = layer.duplicate();
35+
var n_layer = comp.layers.addShape();
3236
n_layer.name = o_prop.name;
37+
copyLayerTransform(layer, n_layer);
3338

3439
// Get the elements of the new layer
3540
var n_layerContents = n_layer.property("Contents");
3641

37-
// Remove all properties different from current original property
38-
for(var k = n_layerContents.numProperties; k > 0; k--) {
42+
insertPropertyToContents(o_prop, n_layerContents, '')
43+
44+
}
45+
46+
}
47+
48+
}
49+
50+
function insertPropertyToContents(prop, contents, prefix) {
51+
52+
if (!contents.canAddProperty(prop.matchName))
53+
return false;
54+
55+
var n_prop = contents.addProperty(prop.matchName)
56+
57+
for(var i=1; i <= prop.numProperties; i++) {
58+
59+
var innerProp = prop.property(i);
60+
61+
if(innerProp.enabled && n_prop.canAddProperty(innerProp.matchName)) {
62+
63+
consLog(prefix + innerProp.matchName);
64+
65+
var p = n_prop.property(innerProp.matchName) ? n_prop.property(innerProp.matchName) : n_prop.addProperty(innerProp.matchName);
66+
67+
switch (innerProp.matchName) {
68+
69+
// case 'ADBE Vector Blend Mode':
70+
71+
case 'ADBE Vector Filter - Merge': // TODO
72+
case 'ADBE Vector Materials Group': // TODO
73+
consLog(prefix + '-- skipped');
74+
break;
75+
76+
case 'ADBE Vector Graphic - Stroke':
77+
copyPropertyStroke(innerProp, p);
78+
break;
79+
80+
case 'ADBE Vector Graphic - Fill':
81+
copyPropertyFill(innerProp, p);
82+
break;
83+
84+
case 'ADBE Vector Transform Group':
85+
copyPropertyTransform(innerProp, p);
86+
break;
87+
88+
case 'ADBE Root Vectors Group':
89+
case 'ADBE Vectors Group':
90+
case 'ADBE Vector Group':
91+
insertPropertyToContents(innerProp, n_prop, prefix += ' ')
92+
break;
93+
94+
case 'ADBE Vector Shape - Group':
95+
copyPropertyShape(innerProp, p);
96+
break;
97+
98+
default:
99+
// TOFIX : Test if setValue is available
100+
p.setValue( innerProp.value );
39101

40-
var n_prop = n_layerContents.property(k);
41102

42-
if(i === k)
43-
continue;
44-
else
45-
n_prop.remove();
46103

47104
}
48105

49106
}
50107

51108
}
52109

110+
53111
}
54112

113+
function copyProperty(name, origin, target) {
114+
target[name].setValue( origin[name].value );
115+
}
116+
117+
function copyPropertyShape(origin, target) {
118+
target.property('ADBE Vector Shape').setValue( origin.property('ADBE Vector Shape').value );
119+
}
120+
121+
function copyPropertyStroke(origin, target) {
122+
123+
copyProperty('composite', origin, target);
124+
copyProperty('color', origin, target);
125+
copyProperty('strokeWidth', origin, target);
126+
copyProperty('lineCap', origin, target);
127+
copyProperty('lineJoin', origin, target);
128+
copyProperty('miterLimit', origin, target);
129+
130+
// TOFIX : dash are present, no mater if deleted or not ! (disabled for now)
131+
if(false && origin.dash.enabled) {
132+
133+
for(var i=1; i <= origin.dash.numProperties; i++) {
134+
135+
var dashProp = origin.dash.property(i);
136+
137+
if(dashProp.enabled)
138+
target.dash.addProperty(dashProp.matchName).setValue(dashProp.value);
139+
140+
}
141+
142+
}
143+
144+
}
145+
146+
function copyPropertyFill(origin, target) {
147+
148+
copyProperty('composite', origin, target);
149+
copyProperty('fillRule', origin, target);
150+
copyProperty('color', origin, target);
151+
152+
}
153+
154+
function copyPropertyTransform(origin, target) {
155+
156+
copyProperty('anchorPoint', origin, target);
157+
copyProperty('position', origin, target);
158+
copyProperty('scale', origin, target);
159+
copyProperty('skew', origin, target);
160+
copyProperty('skewAxis', origin, target);
161+
copyProperty('rotation', origin, target);
162+
copyProperty('opacity', origin, target);
163+
164+
}
165+
166+
function copyLayerTransform(origin, target) {
167+
168+
copyProperty('anchorPoint', origin, target);
169+
copyProperty('position', origin, target);
170+
copyProperty('scale', origin, target);
171+
copyProperty('rotation', origin, target);
172+
copyProperty('opacity', origin, target);
173+
174+
}
175+
176+
function createUI(thisObj) {
177+
178+
if(thisObj instanceof Panel) {
179+
180+
var myPanel = thisObj;
181+
var btn = myPanel.add("button", [10, 10, 100, 30], "Explode layer");
182+
183+
btn.onClick = function() {
184+
explodeLayer( app.project.activeItem.selectedLayers );
185+
}
186+
187+
return myPanel;
188+
189+
} else {
190+
191+
explodeLayer( app.project.activeItem.selectedLayers );
192+
193+
}
194+
195+
}
196+
197+
function consLog(text) { if (configs.log) $.writeln(text); }
198+
199+
var configs = {
200+
log : false,
201+
};
55202

56-
explodeLayer( app.project.activeItem.selectedLayers );
203+
var myToolsPanel = createUI(this);

0 commit comments

Comments
 (0)