Hi,
Tks for your feedback, There is no simple way when you try to make some fct that are not in this original application
So, if someone have the same problem or needs, i have past bellow my functions that i have write to search for expression in the project
with a filter array to ignore some comp or layers, and another array of string that i'm searching in the expression.... maybe it's can help...
Code: Select all
/*HowTo
1st : Defined an array of blacklisted element (comp or layer). element are filter by name or only a part of the name.(empty array = no black list)
exemple : var excludeByName=new Array("Comp 1","*Camera");
2nd : Defined an array of searched string in the expressions (empty array = return all finded expression)
exemple : var expFilters=new Array("ab","try");
3rd : call the master function with this 2 array as parameter
exemple : var result=searchExpression(excludeByName,expFilters);
This exemple will return an array of all properties that have an expression on it with expression that contain "ab" or "try", and that this properties are on a layer or in a comp with a different name than "Comp1" or "*Camera*".
*/
//sub function to search if a string (or part of a string) is in an array of multiple strings
function isInArray(searchedEle,searchArray){
for(var k = 0; k < searchArray.length; k++){
firstChar=searchArray[k].charAt (0);
if(firstChar=="*"){
var strToFind=searchArray[k].slice(1);
var isFind=searchStr(searchedEle,new Array(strToFind));
if(isFind){ return true;}
}else{
if (searchArray[k] == searchedEle) { return true;}
}
}
return false;
}
//sub function to search in a string if one of the string in the array are in it
function searchStr(strToSearchIN,searchedElements){
for(m=0;m<searchedElements.length;m++){
var strPlace=-1;
strPlace=strToSearchIN.search(searchedElements[m]);
if(strPlace !=-1){return true;}
}
return false;
}
//recursive sub function to find properties with expression in a layer
function recursiveScanLayerForExpr(ref){
if (ref != null){
var prop;
for (var i=1; i<=ref.numProperties; i++){
prop = ref.property(i);
if ((prop.propertyType == PropertyType.PROPERTY) && (prop.expression != "") && prop.canSetExpression){
exps.push(prop); // exps need to be defined previously
}
else if ((prop.propertyType == PropertyType.INDEXED_GROUP) || (prop.propertyType == PropertyType.NAMED_GROUP)){
recursiveScanLayerForExpr(prop);
}
}
}
}
//sub function to search expressions (whithout expression filtering)
function ScanProjectForExpr(blackList){
exps= new Array();
//on scan tt les compo et les layers des compo pour renseigner un tableaux des élément
for(var i = 1; i <= app.project.numItems; i++){
var item = app.project.item(i);
if(item instanceof CompItem ){
if(isInArray(item.name,blackList)==false){
alert(item.name);
for (var j = 1; j <= item.numLayers; j++){
if(isInArray(item.layer(j).name,blackList)==false){
recursiveScanLayerForExpr(item.layer(j));
}
}
}
}
}
return exps;
}
//Master function to search expression with blacklist and filters
function searchExpression(excludeByName,expFilters){
var filteredExps=new Array();
var allExps=ScanProjectForExpr(excludeByName);
for(i=0;i<allExps.length;i++){
if(expFilters.length>0){
var expStr=allExps[i].expression;
if(searchStr(expStr,expFilters)){filteredExps.push(allExps[i]);}
}else{
filteredExps.push(allExps[i]);
}
}
return filteredExps;
}
If someone have comments , thanks for that
Mr