Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Find and Replace all expressions in project (or at least all selected comps)?

Explorer ,
Oct 14, 2020 Oct 14, 2020

Hello,

I'm new to AE scripting and I am trying to find or create a script that finds and replaces a string in all expressions in a project.

I found a script that does this but it only searches selected layers, so if you have multiple compositions you have to select all layers and run the script and repeat the process for every composition. I'm finding a wat to make the script go through all layers in all comps, but I'm finding out it's not as simple as it sounds.

I'll post the script I found below in the comments, it's a very helpful script even with it's limitations.
Here's where I found it: https://www.aenhancers.com/viewtopic.php?f=8&t=1225

TOPICS
How to , Scripting
5.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 14, 2020 Oct 14, 2020

Here is the script as it is now: it goes through all the properties in selected layers and searches the expressions for your search term and replaces it with what you typed in the "replace with" field. It doesn't go through multiple comps, though, only the selected layers in the active comp:

 

 

{
app.beginUndoGroup("Search/Replace Expressions");

 

win = new Window('dialog', "Search and Replace Expressions", "x:300,y:300,width:400,height:200");
win.grp1 = win.add('group', "x:0,y:0,width:500,height:500", 'Title of Comp');

win.grp1.add('statictext', "x:15,y:50,width:90,height:20", 'Search Text:');
win.grp1.searchText = win.grp1.add('edittext', "x:100,y:50,width:250,height:20", '<search text>');

win.grp1.add('statictext', "x:15,y:75,width:90,height:20", 'Replace Text:');
win.grp1.replaceText = win.grp1.add('edittext', "x:100,y:75,width:250,height:20", '<replace text>');

win.grp1.changeAllText = win.grp1.add('statictext', "x:15,y:110,width:225,height:20", 'Check to change all expressions:');
win.grp1.changeAllExprCB = win.grp1.add('checkbox', "x:200,y:110,width:20,height:20");

win.grp1.buildBtn = win.grp1.add('button', "x:15,y:150,width:200,height:30", 'Replace Text', {name:'ok'});
win.grp1.buildBtn.onClick = searchProperties;
win.grp1.cancelBtn = win.grp1.add('button', "x:240,y:150,width:100,height:30", 'Close', {name:'cancel'});

win.show();

app.endUndoGroup();
}


function searchProperties()
{

var changeAllCB = win.grp1.changeAllExprCB.value;

clearOutput();

var myComp = app.project.activeItem;

// Gather data
var myLayers = myComp.selectedLayers;
var myCompName = myComp.name;

// Walk layers
if (myLayers.length > 0)
{
for (var l=0; l<myLayers.length; l++) {
var myLayer = myLayers[l];

if (changeAllCB)
findProperties(myLayer);
else
{
selProps = myLayer.selectedProperties;
if (selProps.length > 0)
{
for(var p=0; p<selProps.length; p++)
{
var prop = selProps[p];
searchReplaceExpr(prop);
}
}
else
alert("No properties were selected");
}
}
} else
alert("You must select at least 1 layer");
}

function searchReplaceExpr(prop)
{
var search_text = win.grp1.searchText.text;
var replace_text = win.grp1.replaceText.text;

if (prop.canSetExpression == true) {

var search_text = eval("/" + search_text + "/g");
prop.expression = prop.expression.replace(search_text, replace_text);
}
}

function findProperties(object)
{
var numProps = 0;
numProps = object.numProperties;

// if there are undefined properties, we are at the bottom of the hierarchy of properties
if (numProps == undefined)
{
if (object.expressionEnabled)
searchReplaceExpr(object);
return 1;
} else if (numProps == 0)
return 1;

//recursively search all properties
for (i=1; i<=numProps; i++)
{
findProperties(object.property(i));
}
return 0;
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 14, 2020 Oct 14, 2020

My pt_ExpressEdit script has a search and replace function. You can search the whole project, selected comps, etc:

https://aescripts.com/pt_expressedit/

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 14, 2020 Oct 14, 2020

Thank you, I will check it out.
I am trying to write a simpler, free script to share though. If I'm not able to do so, I will surely buy yours. 

Thanks very much!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 14, 2020 Oct 14, 2020

Sure, I understand. It has lots of nice things in it so worth checking out. You can easily see all the expressions in your project, search in various ways including using logical operators AND, OR & NOT, and you can search/replace either inside that initial search, or just selections from the search results, sort by comp, property, etc. Save and reuse expressions, search for expression errors...lots of good stuff.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 14, 2020 Oct 14, 2020
LATEST

Very good work!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines