Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Closing a Precomp through script

  • Closing a Precomp through script

    Posted by Pritam Bonia on September 10, 2015 at 11:28 am

    Hi,

    I am very new to scripting. Here is what I am trying to do. I have a particular layer in a precomp which has to be replaced with two new layers, which I have been able to do it. But I am unable to close the precomp tab and then close the main project. Below is the code

    I am looking for the precomp “Blinking_Boxes” in the project plane and then duplicating/replacing them. Once the task is done, I am trying to close the comp using “app.project.item(i).close()”. I can close the main project but when I do that and reopen the project with precomp open.

    I want this precomp close as I will be using this script for about 10000 files.

    Can anyone please help me with it?

    var thirdItem= app.project.item(2)
    var fourthItem= app.project.item(3)

    for(i=1; i<=app.project.numItems;i++){
    var secondItem = app.project.item(i);
    if (secondItem.name == “Blinking_Boxes”)
    {
    var mySelection = app.project.item(i);
    app.project.item(i).layer(1).duplicate()
    app.project.item(i).layer(2).duplicate()

    app.project.item(i).layer(2) .replaceSource(thirdItem, true)

    app.project.item(i).layer(3) .replaceSource(fourthItem, true)
    app.project.item(i).layer(1).remove()
    app.project.item(i).layer(2).moveToBeginning()
    theLayer = app.project.item(i).layer(2);
    theLayer.trackMatteType = TrackMatteType.LUMA
    app.project.item(i).close();
    }
    }

    Pritam Bonia replied 10 years, 8 months ago 2 Members · 2 Replies
  • 2 Replies
  • Walter Soyka

    September 10, 2015 at 1:23 pm

    I know you can open a comp in the viewer, but I’m not sure there’s a method for closing it.

    But we can cheat…

    myComp = app.project.item(i); // point to your comp!
    myComp.openInViewer(); // make sure the comp is open and active
    app.executeCommand(app.findMenuCommandId("Close")); // close the window via the UI

    Walter Soyka
    Designer & Mad Scientist at Keen Live [link]
    Motion Graphics, Widescreen Events, Presentation Design, and Consulting
    @keenlive   |   RenderBreak [blog]   |   Profile [LinkedIn]

  • Pritam Bonia

    September 14, 2015 at 5:46 am

    Thanks a lot Walter.

    That worked.

    I failed to mention earlier that I was using CS4, openInViewer() does not work in this version(works only in CS6 I guess). But the closing command did work as it closes whatever comp is open.

    Thanks again.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy