Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Light to each layer selected

  • Light to each layer selected

    Posted by Allen Joaquin on January 10, 2014 at 12:00 pm

    Hello, id like to parent a ¨Light¨ to each layer selected for now i am using this script https://aescripts.com/add-parented-null-to-selected-layers/

    Which adds a null object. is There any way i could modify the contents of it so instead of a null it creates a light.

    This are the contents of it // Add Parented Null to Each Selected Layer.jsx
    // ©July 2009 Lloyd Alvarez https://aescripts.com
    //
    // Creates a new parented Null for every one of the selected layers.
    // You can define what the Suffix name for the null layer is in the user variables below.
    // If you want to include the layer name in the Adj Layer set the variable to 1.
    // To not include the layer name set the variable to 0.
    // *****Note that in CS3 and below After Effects has a 31 character limit for layer names so the name of the
    // Null will be truncated to the first 31 characters ********
    // CS4 does not have a character limit for layers.
    //
    // version history
    // 1.51 fixed "set value" bug Sep 2011
    // 1.5 Checks to see if layer is 3D or parented and sets null at the same position and make it 3D if necessary. Sep 2011
    // 1.0 Initial release. Jul 2009
    //
    //////////////////////////////////////////////////////////////////////
    //
    // USER VARIABLES:
    //
    var nullSuffix = "-Null";
    var addLayerNameBeforeSuffix = 1; // 1 for yes, 0 for no
    //
    //
    //////////////////////////////////////////////////////////////////////

    var proj = app.project;
    var undoStr = "Add Parented Null to Selected Layers";

    if (proj){
    var myComp = app.project.activeItem;
    if (myComp != null && (myComp instanceof CompItem)){
    app.beginUndoGroup(undoStr);

    var myLayers = myComp.selectedLayers;
    var saveIn = 0;
    var saveOut = 0;
    for (i=0; i <= myLayers.length-1; i++){

    currentLayer = myLayers[i];
    saveIn = (currentLayer.stretch < 0) ? currentLayer.outPoint : currentLayer.inPoint;
    saveOut = (currentLayer.stretch < 0) ? currentLayer.inPoint : currentLayer.outPoint;
    saveIndex = currentLayer.index;
    saveName = (addLayerNameBeforeSuffix) ? currentLayer.name+nullSuffix : nullSuffix;

    var myName = (parseFloat(app.version) < 8.0) ? saveName.substring(0, 31) : saveName;
    var newNull = myComp.layers.addNull(myComp.duration);
    if (currentLayer.threeDLayer) newNull.threeDLayer = true;
    var tempParent = null;
    if (currentLayer.parent != null) {
    tempParent = currentLayer.parent;
    var tempLayer = currentLayer.duplicate();
    tempLayer.parent = null;
    newNull.transform.position.setValue(tempLayer.transform.position.value);
    //newNull.transform.scale.setValue(tempLayer.transform.scale.value);
    if (tempLayer.threeDLayer) {

    newNull.transform.xRotation.setValue(tempLayer.transform.xRotation.value);
    newNull.transform.yRotation.setValue(tempLayer.transform.yRotation.value);
    newNull.transform.zRotation.setValue(tempLayer.transform.zRotation.value);
    } else {
    newNull.transform.rotation.setValue(tempLayer.transform.rotation.value);
    }
    tempLayer.remove();
    } else {
    newNull.transform.position.setValue(currentLayer.transform.position.value);
    //newNull.transform.scale.setValue(currentLayer.transform.scale.value);
    if (currentLayer.threeDLayer) {
    newNull.transform.orientation.setValue(currentLayer.transform.orientation.value);
    newNull.transform.xRotation.setValue(currentLayer.transform.xRotation.value);
    newNull.transform.yRotation.setValue(currentLayer.transform.yRotation.value);
    newNull.transform.zRotation.setValue(currentLayer.transform.zRotation.value);
    } else {
    newNull.rotation.setValue(currentLayer.transform.rotation.value);
    }
    }
    if (tempParent != null) newNull.parent = tempParent;
    newNull.moveBefore(myLayers[i]);
    newNull.inPoint = saveIn
    newNull.outPoint = saveOut;
    currentLayer.parent = newNull;
    newNull.name = myName;
    }

    app.endUndoGroup();
    } else {
    alert("Please select an active comp to use this script");
    }
    }
    else
    {
    alert("Please open a project first to use this script.");
    }

    Allen Joaquin replied 12 years, 3 months ago 2 Members · 2 Replies
  • 2 Replies
  • Philip Bowser

    January 10, 2014 at 8:14 pm

    This may do what you’re looking for.


    // USER VARIABLES:
    //
    var nullSuffix = "-Light";
    var addLayerNameBeforeSuffix = 1; // 1 for yes, 0 for no
    //
    //
    //////////////////////////////////////////////////////////////////////

    var proj = app.project;
    var undoStr = "Add Parented Null to Selected Layers";

    if (proj){
    var myComp = app.project.activeItem;
    if (myComp != null && (myComp instanceof CompItem)){
    app.beginUndoGroup(undoStr);

    var myLayers = myComp.selectedLayers;
    var saveIn = 0;
    var saveOut = 0;
    for (i=0; i <= myLayers.length-1; i++){ currentLayer = myLayers[i]; saveIn = (currentLayer.stretch < 0) ? currentLayer.outPoint : currentLayer.inPoint; saveOut = (currentLayer.stretch < 0) ? currentLayer.inPoint : currentLayer.outPoint; saveIndex = currentLayer.index; saveName = (addLayerNameBeforeSuffix) ? currentLayer.name+nullSuffix : nullSuffix; var myName = (parseFloat(app.version) < 8.0) ? saveName.substring(0, 31) : saveName; var centerW = currentLayer.width/2; var centerH= currentLayer.height/2; var newNull = myComp.layers.addLight("",[centerW,centerH]); if (currentLayer.threeDLayer) newNull.threeDLayer = true; var tempParent = null; if (currentLayer.parent != null) { tempParent = currentLayer.parent; var tempLayer = currentLayer.duplicate(); tempLayer.parent = null; newNull.transform.position.setValue(tempLayer.transform.position.value); //newNull.transform.scale.setValue(tempLayer.transform.scale.value); if (tempLayer.threeDLayer) { newNull.transform.xRotation.setValue(tempLayer.transform.xRotation.value); newNull.transform.yRotation.setValue(tempLayer.transform.yRotation.value); newNull.transform.zRotation.setValue(tempLayer.transform.zRotation.value); } else { newNull.transform.rotation.setValue(tempLayer.transform.rotation.value); } tempLayer.remove(); } else { newNull.transform.position.setValue(currentLayer.transform.position.value); //newNull.transform.scale.setValue(currentLayer.transform.scale.value); if (currentLayer.threeDLayer) { newNull.transform.orientation.setValue(currentLayer.transform.orientation.value); newNull.transform.xRotation.setValue(currentLayer.transform.xRotation.value); newNull.transform.yRotation.setValue(currentLayer.transform.yRotation.value); newNull.transform.zRotation.setValue(currentLayer.transform.zRotation.value); } else { newNull.rotation.setValue(currentLayer.transform.rotation.value); } } if (tempParent != null) newNull.parent = tempParent; newNull.moveBefore(myLayers[i]); newNull.inPoint = saveIn newNull.outPoint = saveOut; currentLayer.parent = newNull; newNull.name = myName; } app.endUndoGroup(); } else { alert("Please select an active comp to use this script"); } } else { alert("Please open a project first to use this script."); }

  • Allen Joaquin

    January 11, 2014 at 2:16 am

    ok i actually wanted a point light, so i´ve added the lines

    var newNull = myComp.layers.addLight("",[centerW,centerH]);
    newNull.lightType = LightType.POINT;

    This is how it looks like now.

    // Add Parented Null to Each Selected Layer.jsx

    //
    // USER VARIABLES:
    //
    var nullSuffix = "-Light";
    var addLayerNameBeforeSuffix = 1; // 1 for yes, 0 for no
    //
    //
    //////////////////////////////////////////////////////////////////////

    var proj = app.project;
    var undoStr = "Add Parented Null to Selected Layers";

    if (proj){
    var myComp = app.project.activeItem;
    if (myComp != null && (myComp instanceof CompItem)){
    app.beginUndoGroup(undoStr);

    var myLayers = myComp.selectedLayers;
    var saveIn = 0;
    var saveOut = 0;
    for (i=0; i <= myLayers.length-1; i++){ currentLayer = myLayers[i]; saveIn = (currentLayer.stretch < 0) ? currentLayer.outPoint : currentLayer.inPoint; saveOut = (currentLayer.stretch < 0) ? currentLayer.inPoint : currentLayer.outPoint; saveIndex = currentLayer.index; saveName = (addLayerNameBeforeSuffix) ? currentLayer.name+nullSuffix : nullSuffix; var myName = (parseFloat(app.version) < 8.0) ? saveName.substring(0, 31) : saveName; var centerW = currentLayer.width/2; var centerH = currentLayer.height/2; var newNull = myComp.layers.addLight("",[centerW,centerH]); newNull.lightType = LightType.POINT; if (currentLayer.threeDLayer) newNull.threeDLayer = true; var tempParent = null; if (currentLayer.parent != null) { tempParent = currentLayer.parent; var tempLayer = currentLayer.duplicate(); tempLayer.parent = null; newNull.transform.position.setValue(tempLayer.transform.position.value); //newNull.transform.scale.setValue(tempLayer.transform.scale.value); if (tempLayer.threeDLayer) { newNull.transform.xRotation.setValue(tempLayer.transform.xRotation.value); newNull.transform.yRotation.setValue(tempLayer.transform.yRotation.value); newNull.transform.zRotation.setValue(tempLayer.transform.zRotation.value); } else { newNull.transform.rotation.setValue(tempLayer.transform.rotation.value); } tempLayer.remove(); } else { newNull.transform.position.setValue(currentLayer.transform.position.value); //newNull.transform.scale.setValue(currentLayer.transform.scale.value); if (currentLayer.threeDLayer) { newNull.transform.orientation.setValue(currentLayer.transform.orientation.value); newNull.transform.xRotation.setValue(currentLayer.transform.xRotation.value); newNull.transform.yRotation.setValue(currentLayer.transform.yRotation.value); newNull.transform.zRotation.setValue(currentLayer.transform.zRotation.value); } else { newNull.rotation.setValue(currentLayer.transform.rotation.value); } } if (tempParent != null) newNull.parent = tempParent; newNull.moveBefore(myLayers[i]); newNull.inPoint = saveIn newNull.outPoint = saveOut; currentLayer.parent = newNull; newNull.name = myName; } app.endUndoGroup(); } else { alert("Please select an active comp to use this script"); } } else { alert("Please open a project first to use this script."); }

    But now i come acrros the error on line 77 ¨Can not ¨Set value¨ with this property, because the property of a parent property is ¨Hidden¨

    If i make the layer 3D: Error line 72 ¨can not set value with this property because the property or a parent property is hidden.

    What could i do? i add the notepad of the code since ive had some troubles copying and pasting the code from the website.

    Also mention that before the script stops it creates 1 light correctly even tho i have 3 layers selected.

    6983_script.txt.zip

    Thank you

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