Skip to main content
UQg
Legend
July 18, 2014
Question

autoFixExpressions

  • July 18, 2014
  • 2 replies
  • 2001 views

I'm experiencing issues with app.project.autoFixExpressions() (which is a utility function that attempts to fix expressions that a script may have broken, to be used like this: app.project.autoFixExpressions(oldString, newString) - see guide).

It works most of the time, but not always.

Here is a situation where it does not:

// create a new comp, a solid with a slider control, then duplicate the solid to get 5 solids.

var n, N=5;

var name;

var comp = app.project.items.addComp("test", 1280, 720, 1.0, 5.0, 25.0);

with(comp.layers.addSolid([1,1,0.5], comp.width, comp.height, comp.pixelAspect, comp.duration)){

    name = "solid";

    effect.addProperty("ADBE Slider Control").name = "My Slider";

    effect(1)(1).expression = "thisComp.layer(\"solid\").effect(\"My Slider\")(1).value";

    };

for (n=1; n<N; n++) comp.layer(1).duplicate();

// at this stage, layer(1).name is "solid 5", ... , layer(5).name is "solid".

// all expressions refer to the slider of the last layer.

// rename all solids and try autofix expressions

for (n=1; n<=N; n++){

    name = comp.layer(n).name;

    app.project.autoFixExpressions(name, comp.layer(n).name = name.replace("solid", "gaz"));

    };

// ===> the expression in the last layer is not fixed...

If one replaces the line for (n=1; n<N; n++) comp.layer(1).duplicate(); by

for (n=1; n<N; n++) comp.layer(1).duplicate().effect(1)(1).expression = "thisComp.layer(\"solid " + (++n) +"\").effect(\"My Slider\")(1).value";

(so that now each expression refers to its own layer (same as thisLayer.effect(\"My Slider\")(1).value";), then all expressions are fixed correctly.

Should this be considered as a bug or am i doing something wrong ? I'm lost.

This topic has been closed for replies.

2 replies

Participant
January 7, 2015

Hi there, I'm also running into this issue.  I find it works most of the time, but fails about five to ten percent of the time.  I'm seeing this issue in CS6, CC, and CC2014 (all in OS X).  I'm guessing this is a bug in AE but I've put together an example script that should allow anyone to see the issue for themselves.  Here's how to use it:

1.  Make a new AE project.

2.  Run this script

3.  Click the "Setup Example" button.  A new comp with a couple null layers will be created.  The second layer has an expression linking it to the first layer.

4.  Click back and forth between the "Rename: Blue" and "Rename: Red" buttons (this is renaming layer 1 each time).  At some point the expression should break.  It might only take a couple clicks, or it could take 20.

5.  To speed things up, you can click the "Rename 20x" button.  It will toggle the layer name back and forth 20 times after each click.  Each time the layer is renamed, the autoFixExpressions function is used.

The autoFixExpressions() function is being used at line 26.  Thanks in advance for any help!

Dave Jacobson

function autoFixExpressionsExample() {

  //setup GUI

  win=new Window("palette","autoFixExpressions()",[0,0,170,125],{resizeable:true,});

  setup=win.add("button",[5,5,155,25],"Setup Example");

  rename1=win.add("button",[5,30,155,50],"Rename: Blue");

  rename2=win.add("button",[5,55,155,75],"Rename: Red");

  rename20x=win.add("button",[5,80,155,100],"Rename 20x");

  win.center();

  win.show();

  //button actions

  setup.onClick = function() {setupExample()}

  rename1.onClick = function() {renameLayer("blue")}

  rename2.onClick = function() {renameLayer("red")}

  rename20x.onClick = function() {rename20times()}

  function rename20times() {

  for (var n=0; n<20; n++) {

  renameLayer("blue");

  renameLayer("red");

  }

  }

  function renameLayer(newName) {

  if (app.project.activeItem instanceof CompItem) {

  var oldName = app.project.activeItem.layer(1).name;

  app.project.activeItem.layer(1).name = newName;

  app.project.autoFixExpressions(oldName,newName);

  }

  }

  function setupExample() {

  var newComp = app.project.items.addComp("example", 1920, 1080, 1.0, 1, 23.976);

  newComp.openInViewer();

  newComp.layers.addNull(1);

  newComp.layers.addNull(1);

  newComp.layer(2).property("Position").expression = ("thisComp.layer(\""+newComp.layer(1).name+"\").transform.position");

  }

}

autoFixExpressionsExample();

UQg
UQgAuthor
Legend
January 7, 2015

Hi Dave, i clicked repeatedly on "Rename 20x" and everything was fine: no expression break, and in the info panel the line: Fixed 1 expression(s).

Windows 7, After Effects CC 13.2.0.49

Xavier.

Participant
January 13, 2015

Thank you for testing this Xavier.

Alex White
Legend
July 19, 2014

Works pretty fine for me.

Using AE CC.

UQg
UQgAuthor
Legend
July 20, 2014

Thank you for testing Alex.

I bet that's my version then, CS5.5.

Xavier.