Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Scripting: Create new comp and open it

  • Scripting: Create new comp and open it

    Posted by Ecko Locko on November 7, 2016 at 1:07 pm

    Hi,

    At first i have to say that im pretty new in scripting. Im trying to create a very simple script that makes a new 1080 composition but i want to open the comp after, how can i archieve this?

    I have one more question, hope you can help me..

    When I throw the script, as I can make the edittext field stay in focus to write directly and when pressing the return key the onclick event takes place?

    Thanks!

    var proj = app.project;
    var undoStr = "Crear Nueva Composición 1080p";

    if (proj){
    var myComp = app.project.items;

    app.beginUndoGroup(undoStr);

    win=new Window("palette","Crear nueva Composición",undefined,{resizeable:false,});
    panel_1=win.add("panel",[5,5,285,149]);
    panel_1.graphics.backgroundColor = panel_1.graphics.newBrush (panel_1.graphics.BrushType.SOLID_COLOR,[0.51,0.51,0.51]);
    but_1=panel_1.add("button",[70,97,210,123],"Aceptar");
    edittext_1=panel_1.add("edittext",[40,50,240,78] ,"",{readonly:0,noecho:0,borderless:0,multiline:0,enterKeySignalsOnChange:0});
    edittext_1.graphics.foregroundColor = edittext_1.graphics.newPen (edittext_1.graphics.PenType.SOLID_COLOR,[0,0,0], 1);
    edittext_1.graphics.backgroundColor = edittext_1.graphics.newBrush (edittext_1.graphics.BrushType.SOLID_COLOR,[0.73,0.85,0.87]);
    statictext_1=panel_1.add("statictext",[69,22,330,42] ,"Nombre de la Composicion",{multiline:true});
    statictext_1.graphics.foregroundColor = statictext_1.graphics.newPen (statictext_1.graphics.PenType.SOLID_COLOR,[0,0,0], 1);
    win.center();
    win.show();

    but_1.onClick = function ()
    {
    if (edittext_1.text=="")
    {
    alert("Debes de escribir un nombre para la composicion");
    } else {
    myComp.addComp(edittext_1.text, 1920, 1080, 1, 15, 25);
    win.close();
    }
    }

    app.endUndoGroup();

    }
    else
    {
    alert("Please create a project before");
    }

    Xavier Gomez replied 9 years, 6 months ago 2 Members · 5 Replies
  • 5 Replies
  • Xavier Gomez

    November 7, 2016 at 2:20 pm

    Use openInViewer():

    myComp.addComp(edittext_1.text, 1920, 1080, 1, 15, 25).openInViewer();

    Xavier

  • Ecko Locko

    November 7, 2016 at 2:34 pm

    Thanks Xavier,

    Do you know how i can put keyboard focus on Edit Text Field when launch script and if i hit the Enter key button the onClick event start?

    I saw a lot of scripts doing this, i want to launch the script, put the name of the comp and exit clicking Enter key, is this possible?

    Im trying .active property but doesnt work, i dont know what happens, i still trying…

    Gracias.

  • Xavier Gomez

    November 7, 2016 at 3:57 pm

    For me “active” works:

    win.show();
    edittext_1.active=true;

    And to automatically trigger onClick when the enter key is pressed, you can use:

    edittext_1.onEnterKey = function(){but_1.notify();};

    Xavier

  • Ecko Locko

    November 7, 2016 at 4:14 pm

    Dont know why didnt work for me before but now is just perfect!!!

    Thanks a lot Xavier, have a nice day!

  • Xavier Gomez

    November 7, 2016 at 4:33 pm

    I forgot to say that there is the ready-to-use function : prompt

    var compName = prompt("Enter the new comp name:", "Some name to start with", "Hi");
    if (compName){
    app.beginUndoGroup("Crear Nueva Composición 1080p");
    app.project.items.addComp(compName, 1920, 1080, 1, 15, 25).openInViewer();
    app.endUndoGroup();
    };

    Xavier

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