Copy link to clipboard
Copied
Hello everyone ,
i have a comp with many type a file(png,swf....),and i want to use only the swf one ,
put them at the end and distribute them by name using the first part of the name ..
(00_file01.swf 01_file01.swf 02_file02.swf 03_file03.swf.........)
I try to do that :
...
here the others files...
...
.....
02_file02.swf
01_file01.swf
00_file01.swf
i do that code for the moment but i dont know how to check the first part of the name and continue the loop...
//step01
for (i=0;i<app.project.activeItem.layers.length;i++) {
if ((app.project.activeItem.layer(i+1).name.toLowerCase().indexOf('.swf') != -1)&& (app.project.activeItem.layer(i+1).name.split("_")[0]=="00"))
app.project.activeItem.layer(i+1).selected = true;
}
app.project.activeItem.selectedLayers[0].moveToEnd();
var Swf_00=app.project.activeItem.selectedLayers[0].index
var PosSwf00=app.project.activeItem.layer(Swf_00)
//#selectNone
for (i=0;i<app.project.activeItem.layers.length;i++) {
app.project.activeItem.layer(i+1).selected = false;
}
//step02
for (i=0;i<app.project.activeItem.layers.length;i++) {
if ((app.project.activeItem.layer(i+1).name.toLowerCase().indexOf('.swf') != -1)&& (app.project.activeItem.layer(i+1).name.split("_")[0]=="01"))
app.project.activeItem.layer(i+1).selected = true;
}
app.project.activeItem.selectedLayers[0].moveBefore(PosSwf00);
var Swf_01=app.project.activeItem.selectedLayers[0].index
//step03
for (i=0;i<app.project.activeItem.layers.length;i++) {
if ((app.project.activeItem.layer(i+1).name.toLowerCase().indexOf('.swf') != -1)&& (app.project.activeItem.layer(i+1).name.split("_")[0]=="02"))
app.project.activeItem.layer(i+1).moveBefore(app.project.activeItem.layer(Swf_01));
}
Give this one a shot.
...(function(){
try {
var composition = app.project.activeItem;
if (!composition || !(composition instanceof CompItem))
return alert("Please select composition first");
var swfFiles = getLayersByName(composition, ".swf");
if (swfFiles.length === 0) {
return alert("Composition contains no SWF files.");
}
var sortedByName = sortFilesByPrefix(swfFiles, "_");
app.beginUndoGroup("Sort them");
Copy link to clipboard
Copied
Give this one a shot.
(function(){
try {
var composition = app.project.activeItem;
if (!composition || !(composition instanceof CompItem))
return alert("Please select composition first");
var swfFiles = getLayersByName(composition, ".swf");
if (swfFiles.length === 0) {
return alert("Composition contains no SWF files.");
}
var sortedByName = sortFilesByPrefix(swfFiles, "_");
app.beginUndoGroup("Sort them");
for (var i = 0, il = sortedByName.length; i < il; i ++) {
sortedByName.moveToEnd();
}
app.endUndoGroup();
} catch (e) {
alert (e.toString() + "\nScript File: " + File.decode(e.fileName).replace(/^.*[\|\/]/, '') +
"\nFunction: " + arguments.callee.name +
"\nError on Line: " + e.line.toString());
}
function getLayersByName(composition, nameSnippet) {
var layersThatMachCriteria, layer;
layersThatMachCriteria = [];
for (var i = 1, il = composition.numLayers; i < il; i ++) {
layer = composition.layer(i);
if (layer.name.toLowerCase().match(nameSnippet)) {
layersThatMachCriteria.push(layer);
}
}
return layersThatMachCriteria;
}
function sortFilesByPrefix(swfFiles, separator) {
var sortedArray, layerName, indexAsString, indexAsInteger;
sortedArray = [];
for (var i = 0, il = swfFiles.length; i < il; i ++) {
layerName = swfFiles.name;
indexAsString = layerName.split(separator)[0];
indexAsInteger = parseInt(indexAsString);
sortedArray[indexAsInteger] = swfFiles;
}
return sortedArray;
}
})();
Copy link to clipboard
Copied
Thank you so much Tomas its works well !!!!