Skip navigation
Currently Being Moderated

"new comp from selection"

Mar 26, 2012 1:52 AM

hi i need to find out the expression for creating a comp from a selected item in the project panel.

 

i know there is an option in after effects in file -> new comp from selection. but i need it as part of a script, and so that it automatically sets the dimensions of the comp to any item in the selection

 

 

can anyone please help meeeeeee.x

 

Sam

 
Replies
  • Currently Being Moderated
    Mar 26, 2012 2:08 AM   in reply to samwilliams21

    You have to roll your own but it's easy enough.

     

    if (app.project.selection.length == 1) {

              var sourceItem = app.project.selection[0];

              app.project.items.addComp(sourceItem.name + " copy", sourceItem.width, sourceItem.height, sourceItem.pixelAspect, sourceItem.duration, sourceItem.frameRate);

    } else {

              alert("select one item in project window");

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 26, 2012 3:52 PM   in reply to samwilliams21

    Yes, I was just giving you an example to get you started. I'd generally suggest checking out AE's CS3 scripting guide and the Javascript Tools Guide pdfs for documentation, and posting questions along with your code so far when you get stuck. You can study the various examples on here and places like aenhancers.com to get a better understanding of the syntax.

     

    And one minor point, expressions (javascript that controls a property value) and scripting (javascript that controls After Effects) aren't exactly the same thing. In this case we're talking about scripting, not expressions.

     

    Here's an example that should be closer to what you want:

     

    var frameRate = 30;

    var maxDuration = 10;

    var maxWidth = 10;

    var maxHeight = 10;

    var pixelAspect = 1;

     

    var x,y, curItem, thisItem, theComp;

     

    for (x = 1;  x <= app.project.rootFolder.numItems; x++) {          // loop through items in root folder only

              curItem = app.project.rootFolder.item(x);

              if (curItem.selected && curItem instanceof FolderItem) {          // if it's selected and a folder

                        for (y = 1; y <= curItem.numItems; y++) {          // loop through the folder's items

                                  thisItem = curItem.item(y);

                                  if (thisItem instanceof FootageItem) {          // if it's footage

                                            if (thisItem.hasVideo) {          // if it has video

                                                      maxWidth = Math.max(maxWidth, thisItem.width);          // record this footage width if largest

                                                      maxHeight = Math.max(maxHeight, thisItem.height);          // record this footage height if largest

                                                      pixelAspect = thisItem.pixelAspect;                    // record aspect ratio

                                                      if (!thisItem.mainSource.isStill) {          // if it isn't a still record frame rate and duration if longest

                                                                maxDuration = Math.max(maxDuration, thisItem.duration);

                                                                frameRate = thisItem.frameRate;

                                                      }

                                            } else {          // must be audio. record duration if longest

                                                      maxDuration = Math.max(maxDuration, thisItem.duration);

                                            }

                                  }

                        }

                        theComp = app.project.items.addComp(curItem.name, maxWidth, maxHeight, pixelAspect, maxDuration, frameRate);          // add comp with max values and folder name

     

                        for (y = 1; y <= curItem.numItems; y++) {          // loop through items in folder again, adding them to comp if they are footage

                                  thisItem = curItem.item(y);

                                  if (thisItem instanceof FootageItem) {

                                            theComp.layers.add(thisItem);

                                  }

                        }

              }

    }

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points