Forum Replies Created

  • I edited the code just a little :

    {

    app.beginUndoGroup("Pre-Compose to Layer Duration");

    var myComp = app.project.activeItem;

    var copySelected = myComp.selectedLayers.slice();

    if(myComp instanceof CompItem) {

    var myLayers = myComp.selectedLayers;

    if(myLayers.length > 0){

    var newIndex = copySelected[copySelected.length-1].index;

    var myNewInPoint = copySelected[0].inPoint;

    var newInPoint = myLayers[0].inPoint;

    var newOutPoint = myLayers[0].outPoint;

    var newCompName = "comp ";

    var layerName = myLayers[0].name;

    if(layerName.length > 26) {

    layerName = layerName.substring(0, 26);

    }

    newCompName += layerName;

    var layerIndices = new Array();

    for (var i = 0; i < myLayers.length; i++) {

    layerIndices[layerIndices.length] = myLayers[i].index;

    if (myLayers[i].inPoint < newInPoint) newInPoint = myLayers[i].inPoint;

    if (myLayers[i].outPoint > newOutPoint) newOutPoint = myLayers[i].outPoint;

    }

    var newComp = myComp.layers.precompose(layerIndices, newCompName, true );

    var preCompLayer = myComp.selectedLayers[0];

    preCompLayer.outPoint = newOutPoint;

    newComp.workAreaStart = newInPoint;

    newComp.duration = newOutPoint;

    newComp.openInViewer().setActive();

    app.executeCommand(app.findMenuCommandId("Trim Comp to Work Area"));

    myComp.openInViewer().setActive();

    myComp.layer(newIndex).startTime = myNewInPoint;

    }else{

    alert("select at least one layer to precompose.");

    }

    }else{

    alert("please select a composition.");

    }

    app.endUndoGroup();

    }

    but the problem with this code is that you have to select the layers from bottom to top or
    you will get an error
    maybe someone could enhance it ?

  • Baqer Asad

    March 10, 2021 at 6:28 pm in reply to: ExtendScript index

    Thank you so much!

    I would ask 2 more things and I woulf be greatfull if you can answer them.
    now I made the inPoint and outPoint the same as the selected layer and it works,but if I selected multiple layers and do the changes in photo2, it will give me an error,I think I can’t change the inPoint value even if I declared it as a variable so how can I get around it ?
    and the second problem is the parenting , I parented it as shown in the picture but it’s working backward ,I want to make the layer parented to the new null and the new null to the newer one if possible.
    sorry if that was a lot to ask but thank you very much. 🙂

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