linked expression

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
tapsystem
Posts: 21
Joined: February 19th, 2013, 2:44 pm

Hi,

i have some effect color controls that are used to store a color value and pointed in different effect by expression.

I want to add in my script a function to return the number of links to this controller (expressions that are pointing this value), is there a simple way to do that ?

Tks :wink:
Mr
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

You would have to get the script to look through all the layers in the relevant comp/comps looking for any properties that contain expressions. Depending on what you're doing, this could just be looking at effect properties. If you have expressions linked to different color values you'll have to analyse the expression to work out which property it is pointing to.

There isn't a simpler way to do it.

Paul
tapsystem
Posts: 21
Joined: February 19th, 2013, 2:44 pm

Hi,

Tks for your feedback, There is no simple way when you try to make some fct that are not in this original application :D

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 :wink:

Mr
Post Reply