Open composition in the timeline via scripting?

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
ScottHD
Posts: 11
Joined: June 14th, 2008, 9:22 pm
Location: South Carolina

Is there a way to open a composition into an empty timeline via scripting without manually double-clicking the composition in the project window in After Effects?
My current script below does everything I need it to do in the "Begin Create Faux Logo Comp" section. But won't execute the "Begin Set color of Text via Layer Styles" section of the script because the composition created in the previous section does is not open in the timeline. If I open the composition into the timeline manually and run the "Begin Set color of Text via Layer Styles" section of code by-itself it does what I need it to do.

I've tried a few things but just can't seem to get it to work.

Code: Select all

//-------*Begin What this script needs to do*---------------//
//To create Faux Logos:
//Create a folder named, Company Web Logo.
//Create a 200x70 (or 250x100) size composition inside of that folder.
//Add a basic black Text Layer with "Faux Logo" as the source text in the middle.
//-------*End What this script needs to do*---------------//

//-----------Begin Create Faux Logo Comp--------------//
function projectItem(name)
{
var items = app.project.items;
i = 1;
while (i <= items.length) {
  if (items[i].name == name)
 {
  return app.project.item(i);
  break;
  }
i++;
}
}
app.project.items.addFolder("Company Web Logo");
var myComp = projectItem("Company Web Logo").items.addComp("Logo Comp", 200, 70, 1.0, 1.0, 25.0);
var mySolid = myComp.layers.addSolid( [255,255,255], "White Solid", 200, 70, 1.0,1.0);
var myText = myComp.layers.addText( "Faux Logo");
var halfcompW = 0.5*(app.project.item(2).width);
var halfcompH = 0.5*(app.project.item(2).height);
myText.transform.position.setValue([200,80]);
myText.transform.anchorPoint.setValue([halfcompW,halfcompH]);
//-----------End Create Faux Logo Comp--------------//

//-----------Begin Set color of Text via Layer Styles--------------//
var firstLayer = app.project.item(2).layer(1);
firstLayer.selected = true;
app.executeCommand(app.findMenuCommandId("Color Overlay"));
firstLayer.layerStyle.colorOverlay.color.expression = "layerStyle.colorOverlay.color = [0,0,0,1]";
//-----------Begin Set color of Text via Layer Styles--------------//
Any help is appreciated! :D
ScottHD
Posts: 11
Joined: June 14th, 2008, 9:22 pm
Location: South Carolina

Is this do able or am I just not explaining what I need the script to do properly?

Thanks!
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

Scripts can't do things like opening compositions (unfortunately). And app.executeCommand exactly mimics what would happen if you select something from the menu, so you're right that it'll only work on an open comp.

But really, your question is "Is it possible to apply a layer style using a script?". I thought it would be something simple like this, but it doesn't work:

Code: Select all

firstLayer.property("Layer Styles").addProperty("Color Overlay");
The best I could come up with is to save a Color Overlay as an animation preset, placed in the same folder as the script, and then use this code to replace app.executeCommand:

Code: Select all

var thePreset = new File ("Color Overlay.ffx");
firstLayer.applyPreset(thePreset);
Paul
ScottHD
Posts: 11
Joined: June 14th, 2008, 9:22 pm
Location: South Carolina

Thanks Paul for your reply!

I will go try the preset option you presented.
ScottHD
Posts: 11
Joined: June 14th, 2008, 9:22 pm
Location: South Carolina

I was looking at the Creative Cow forums tonight and noticed a post by the user "rich helvey" asking for a very similar functionality: http://forums.creativecow.net/thread/227/10710
He found an undocumented workaround: ramPreviewTest()

It worked when I inserted it in the //-----------Begin Create Faux Logo Comp--------------// section of my script above and modified to fit a little to fit my need and for speed.

Code: Select all

//-----------Begin Create Faux Logo Comp--------------//
function projectItem(name)
{
var items = app.project.items;
i = 1;
while (i <= items.length) {
  if (items[i].name == name)
 {
  return app.project.item(i);
  break;
  }
i++;
}
}
app.project.items.addFolder("Company Web Logo");
var myComp = projectItem("Company Web Logo").items.addComp("Logo Comp", 200, 70, 1.0, 1.0, 29.97);
var mySolid = myComp.layers.addSolid( [255,255,255], "White Solid", 200, 70, 1.0,1.0);
var myText = myComp.layers.addText( "Faux Logo");
var halfcompW = 0.5*(app.project.item(2).width);
var halfcompH = 0.5*(app.project.item(2).height);
var duration = myComp.workAreaDuration;
myText.transform.position.setValue([200,80]);
myText.transform.anchorPoint.setValue([halfcompW,halfcompH]);

myComp.workAreaDuration = 1.0; 
myComp.ramPreviewTest(1.0,1.0,0);
myComp.workAreaDuration = duration; 
//-----------End Create Faux Logo Comp--------------//
It does take a less than a second to Ram Preview the shortened workarea before resetting the work area duration back to the original duration.

"rich helvey" on the creative cow forum wasn't able to figure out what the 1st and 3rd values controlled in this object.
So, after a few tests, there seems to be a maximum of three values that can be put into the parenthesis area of the ramPreviewTest() object:
ramPreviewTest(???,Magnification Ratio Popup,Adjust Exposure control)
--The first value seems to relate to the workAreaDuration value somehow.
--The second value sets the Magnification Ratio Popup percentage (Zoom value of the active composition viewer). A value of 1 puts it at 100%. A value of 0.5 puts it at 50%. A value of 2 puts it at 200%. Etc.
--The third value sets the Adjust Exposure control in Composition viewer. The range is -40 to 40.

Maybe someone out there can find out what that first value truly controls.
Hope this info helps someone as it did me. :-)
SanLion
Posts: 1
Joined: January 17th, 2014, 10:36 pm

.openInViewer method will help you

Post Reply