Expressions/Scripts/Presets

Moderator: byronnash

 
Navstar
Topic Author
Posts: 68
Joined: Mon Feb 16, 2009 12:41 pm

Put nulls at each corner of a solid

Fri Jun 15, 2012 11:44 am

Not much more to explain.

For every Solid I have selected (2D or 3D), put a null in each corner. :D
 
dfred
Posts: 29
Joined: Fri Jul 23, 2010 11:49 pm

Re: Put nulls at each corner of a solid

Fri Jun 15, 2012 1:07 pm

Try the attached script.

// CornerNulls.jsx by Dan Fredley ©2012
// Version 1.0
// This script creates a null object at each corner of selected layers and keeps them organized in a "Nulls" folder within the "Solids" folder.
//
// No scripts are guaranteed and use at your own risk, etc.
{
    function CornerNulls ()
    {
        app.beginUndoGroup("CornerNulls");    // create script undo group
        var proj = app.project;
        var comp = proj.activeItem;
        var layer, len, myNull, solidsFolder, nullsFolder, item, myNull1, myNull2, myNull3, myNull4, nullDuration;
        var foundSolids = foundNullsFolder = false;
        var myItemCollection = app.project.items;
        var sel = new Array();
        var compNulls = [];
     
        if (!(comp instanceof CompItem)) {
            alert("Please select a composition.");
            return;
        } else if (comp.selectedLayers.length < 1) {
            alert("Please select at least one layer.");
            return;
        } else {
          sel = comp.selectedLayers;
          nullDuration = comp.duration;  // change to the number of seconds or comp.duration for length of comp
        }
        for (i=1;i<=proj.numItems;i++){  //loop through project items to find solids folder
          item = myItemCollection[i];
            if (item.name == 'Solids' && item instanceof FolderItem && item.parentFolder == app.project.rootFolder){
                foundSolids = true;
                solidsFolder = item;
                break;
            }
        }
        if (foundSolids) {
            for (i=1;i<=solidsFolder.numItems;i++){ // loop through solidsFolder to find Nulls folder and null object
                item = solidsFolder.items[i];
                if (item.name == "Nulls" && item instanceof FolderItem){  //  look for Nulls folder
                    foundNullsFolder = true;
                    nullsFolder = item;
                    continue;
                }
            }
        } else {
            solidsFolder = proj.items.addFolder('Solids');
        }
        if (!foundNullsFolder) nullsFolder = solidsFolder.items.addFolder('Nulls'); // if no nulls folder was found create one   
        for (i=0, len = sel.length; i < len; i++){  //loop through selected layers
          layer = sel[i].name;
         
          myNull1 = comp.layers.addNull(nullDuration);
          myNull1.parent = sel[i];
          myNull1.position.expression = """[0,0]""";
          myNull1.name = sel[i].name + " TL";
          myNull1.source.parentFolder = nullsFolder;
          myNull1.moveBefore(sel[i]);
          myNull1.inPoint = sel[i].inPoint;
          myNull1.outPoint = sel[i].outPoint;
          myNull1.threeDLayer = sel[i].threeDLayer;
         
          myNull2 = comp.layers.addNull(nullDuration);
          myNull2.parent = sel[i];
          myNull2.position.expression = 'L=thisComp.layer("' + sel[i].name + '");\r[L.width,0]';
          myNull2.name = sel[i].name + " TR";
          myNull2.source.parentFolder = nullsFolder;
          myNull2.moveBefore(sel[i]);
          myNull2.inPoint = sel[i].inPoint;
          myNull2.outPoint = sel[i].outPoint;
          myNull2.threeDLayer = sel[i].threeDLayer;         
         
          myNull3 = comp.layers.addNull(nullDuration);
          myNull3.parent = sel[i];
          myNull3.position.expression = 'L=thisComp.layer("' + sel[i].name + '");\r[L.width,L.height]';
          myNull3.name = sel[i].name + " BR";
          myNull3.source.parentFolder = nullsFolder;
          myNull3.moveBefore(sel[i]);
          myNull3.inPoint = sel[i].inPoint;
          myNull3.outPoint = sel[i].outPoint;
          myNull3.threeDLayer = sel[i].threeDLayer;         
         
          myNull4 = comp.layers.addNull(nullDuration);
          myNull4.parent = sel[i];
          myNull4.position.expression = 'L=thisComp.layer("' + sel[i].name + '");\r[0,L.height]';
          myNull4.name = sel[i].name + " BL";
          myNull4.source.parentFolder = nullsFolder;
          myNull4.moveBefore(sel[i]);
          myNull4.inPoint = sel[i].inPoint;
          myNull4.outPoint = sel[i].outPoint;
          myNull4.threeDLayer = sel[i].threeDLayer;         
        }
        app.endUndoGroup();
    }
    CornerNulls();
}
Attachments
CornerNulls.jsx.zip
// CornerNulls.jsx by Dan Fredley ©2012
// Version 1.0
// This script creates a null object at each corner of selected layers and keeps them organized in a "Nulls" folder within the "Solids" folder.
//
// No scripts are guaranteed and use at your own risk, etc.
(1.27 KiB) Downloaded 290 times
 
bradon
Posts: 2
Joined: Tue Nov 15, 2005 10:04 am

Re: Put nulls at each corner of a solid

Tue Jun 23, 2015 1:25 pm

This is great! Except can we also get this to work with a shape layer?

The nulls will position on the Bounding box of the shape layer?

Who is online

Users browsing this forum: No registered users and 2 guests