Forum Replies Created

  • Jake Bartlett

    July 26, 2011 at 6:22 pm in reply to: Script to duplicate and offset layers

    Thanks again for your pointers Brian. I got a little further with your help, but still don’t have a completely functional script. I started a thread at aenhancers a couple of weeks ago but I’ve had no responses, so I guess I’ll repost my questions here.

    What I have so far is a script that will duplicate a selected 3D text layer a specified number of times, create a null with a slider control, and add an expression to each text layer linking the z-axis anchor point to the null’s slider control. This allows me to control the look of an extrusion with the slider, and to add more density, all I have to do is duplicate any of the text layers as many more times as needed and they are automatically offset evenly. It’s very helpful already. However, it has some issues. You can access the script here: 2689_anchorpointoffset.jsx.zip

    If I want to run the script on more than one text layer, it creates a null with the same name. That messes with the expression and all of the text layers I’ve created with the script follow the null that was created last. This prevents me from being able to have animated extrusion or different values of extrusion per 3D text. So my first question is…

    1. How do I get the script to generate a unique name for the null every time I run the script?

    The next issue I’ve been trying to figure out is how to parent all of the duplicate text layers to the original? Actually, the way the script works now, the first duplicate layer doesn’t have the expression applied, and leaves the anchor point set to 0. So that layer would probably be my first choice of which layer to parent the duplicates (and in that case, the original) to, but either would work equally. So for the sake of consistency…

    2. How do I parent all of the duplicate layers to the original?

    And finally, I’ve noticed that if I set any parameters for the text’s orientation, after running the script, they are all reset back to 0.

    3. Can the script leave all pre-set attributes alone?

    Thanks in advance for reading this. I don’t know the first thing about writing my own script, this is just something I’ve taken on for myself and my co-workers as it would automate this tedious task each of us have to do on a daily basis.

    https://whoknew.news.yahoo.com

  • Jake Bartlett

    July 15, 2011 at 7:21 pm in reply to: Script to duplicate and offset layers

    Brian,

    Thanks so much! Your script is very close to what I was trying to automate. I managed to chop it down to the only property I need to be able to offset; the z-axis anchor point.

    // Create the palette-type window (a modeless dialog)
    var win = new Window('palette', '3D Layer Offset');
    this.windowRef = win;
    // Create a container panel for the components
    win.pnl = win.add("panel", [5,5,170,80], 'Offset Controls');
    // Use the panel's add() method to create components
    win.pnl.stxt=win.pnl.add('statictext',[10,15,100,35],"Duplicate #:");
    var theNum = win.pnl.add('edittext', [90,15,140,35], '10');
    // Add OK/Cancel buttons
    win.pnl.okBtn = win.pnl.add("button", [10,40,60,60], 'OK');
    win.pnl.cnlBtn = win.pnl.add("button", [90, 40, 140, 60], 'Cancel');
    // Define the behavior of the buttons
    win.pnl.okBtn.onClick = function()
    {
    //alert("button pressed"); //debug
    offset3D();
    }
    win.pnl.cnlBtn.onClick = function()
    {
    $.writeln("Cancel Button Pressed");
    win.close();
    }
    // Display the window
    win.show();
    function on_textInput_changed()
    {
    // Set the duplicate number based on the text.
    //alert("In text change");// debug
    var value = theNum.text;
    if (isNaN(value)) {
    alert(value + " is not a number. Please enter a number.", scriptName);
    } else {
    //alert("Value is "+value);//debugging
    theNumVal = value;
    }
    }
    function offset3D() {
    //alert("In 3D");
    var undoStr = "3D Layer Offset";
    app.beginUndoGroup(undoStr);// begin UNDO group
    on_textInput_changed();//check that its a number not letters
    // alert(theNumVal);//debugging
    var myComp = app.project.activeItem;
    if (myComp == null || !(myComp instanceof CompItem)) { // A COMP MUST BE SELECTED
    alert("A Comp must be active to run this script");
    } else {
    var myLayer = myComp.selectedLayers;
    if (myLayer == null) {// check a layer is selected
    alert ("Select a Layer");
    }else{
    var thisLayer = myComp.selectedLayers[0];
    if(thisLayer){
    thisLayer.threeDLayer = true;
    thisLayer.duplicate();
    // make a null object
    var controlNull = myComp.layers.addNull();
    controlNull.source.name = "Anchor Point Offset Control";
    //add a sliders for Z anchorPoint
    var offset = controlNull("Effects").addProperty("Slider Control");
    offset.name = 'Layer Offset (Z)';
    // duplicate the layers and
    // add the script to the selected layer
    for (i = 0; i < (theNumVal-1); i++) {
    var posExpression = 'x =anchorPoint[0]; \n y=anchorPoint[1];\n z =thisComp.layer(index-1).transform.anchorPoint[2]+ thisComp.layer("Anchor Point Offset Control").effect("Layer Offset (Z)")("Slider");[x,y,z]';
    thisLayer.anchorPoint.expression = posExpression;
    thisLayer.duplicate();
    }
    }else{
    alert("Select a layer first.")
    app.endUndoGroup();
    }
    }
    }
    }

    This is already extremely helpful because of the ability to duplicate layers after running the script, and having them automatically offset. My next question, however, is would it be possible to have the script parent all of the duplicate layers to the original? If the layers are parented, I only have to animate the parent layer. That makes my job a lot more efficient.

    Again, thanks so much for your script. It’s already helping me work more efficiently.

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