Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Reloading the “Create UI” code

  • Reloading the “Create UI” code

    Posted by Mateo Mazzini on December 28, 2012 at 2:27 am

    Sorry for my English, is not my native tongue.
    I’m creating an UI of a script using functions and conditionals, so depending on what I select from the menu (dropdownlist), the UI I’ll see.
    However, once the interface is created, the script only adds the new UI on top the previous.
    Is there a way to tell After Effects that you want to reload the “return window” of the main function that’s creating the main UI, so it only creates the “window.add” that conditionals are describing, and make dissapear the interfaces it added before?

    Thanks!

    Matz

    function createUI(thisObj)
    {
    var ventana = (thisObj instanceof Panel) ? thisObj : new Window(“palette”, “mi Script”, [100, 100, 300, 300], {resizeable:true});

    ventana.add(“statictext”,[10, 10, 90, 30],”Tool”);
    var toolMenu=ventana.add(“dropdownlist”,[100, 10, 195, 30],[“A”,”B”,”C”,”D”,”E”]);
    toolMenu.selection=1;

    toolMenu.onChange=function fcreateUIS(){
    var toolSelection = toolMenu.selection.index;
    //EMPIEZA EL CREADOR DE INTERFACES
    if(toolSelection==0){
    ventana.add(“statictext”,[10, 40, 90, 60], “A TOOL”);
    ventana.add(“edittext”,[100,40,180,60],”Sin Nombre”);
    };
    if(toolSelection==1){
    ventana.add(“statictext”,[10, 40, 90, 60], “B TOOL”);
    ventana.add(“edittext”,[100,40,180,60],”Sin Nombre”);
    };

    };
    //TERMINA EL CREADOR DE INTERFACES

    return(ventana);
    }

    var pal = createUI(this);
    pal;

    Mateo Mazzini replied 13 years, 4 months ago 2 Members · 4 Replies
  • 4 Replies
  • Xavier Gomez

    December 30, 2012 at 11:22 am

    I don’t know if it is a good idea to add/remove items from the palette once it is created and shown. But there is another possiblility:
    Use groups in ‘stack’ (instead of ‘row’ or ‘column’) orientation and play with the visiblity of subgroups.

    for instance:

    ventana.stackgroup = ventana.add(“group {orientation: ‘stack’}”);

    ventana.stacksubgroup1 = ventana.stackgroup.add(“group {orientation:’row’}”);
    ventana.stacksubgroup1.add(“statictext”,[10, 40, 90, 60], “A TOOL”);
    ventana.stacksubgroup1.add(“edittext”,[100,40,180,60],”Sin Nombre”);

    ventana.stacksubgroup2 = ventana.stackgroup.add(“group {orientation:’row’}”);
    ventana.stacksubgroup2.add(“statictext”,[10, 40, 90, 60], “B TOOL”);
    ventana.stacksubgroup2.add(“edittext”,[100,40,180,60],”Sin Nombre”);

    Then in the onChange() function you specify the visibility of subgroups:

    ventana.stacksubgroup1.visible = (toolSelection==0);
    ventana.stacksubgroup2.visible = (toolSelection==1);

    ———–
    Acutally if your selection list is big you can organize subgroups in arrays.
    Create an array of selections (of length, say, numSelectionItems), an array of names (for static text) another array (say: sinNombre) for edit text,then:

    ventana.stacksubgroup = [];
    for (var k=0; k

  • Mateo Mazzini

    December 30, 2012 at 8:13 pm

    Xavier, your method worked just fine. But once again, the problem I found was that I must define the exact coordinates of the elements, because if I don’t, after effects doesn’t know where to put the UI stuff.
    I don’t know if that is a problem that could be solved with alignment code like “row”,”center”… the only way I could make it work was with coordinates…

    leave you with the code i have so far…

    thank’s a lot!

    // DEFINO POSICION DE VENTANA
    puntoX1=10;
    puntoX2=220;
    puntoY1=10;
    puntoY2=500;
    // DEFINO TAMAÑO DE VENTANA
    tamanoX=220;
    tamanoY=500;

    ////////////////////////////////////////////////////////////////////

    function createUI(thisObj)
    {
    var ventana = (thisObj instanceof Panel) ? thisObj : new Window(“palette”, “my script”, [100, 100, 300, 300], {resizeable:true});

    ventana.stackgroup = ventana.add(“group”);
    ventana.stackgroup.location=[puntoX1,puntoY1,puntoX2,puntoY2];
    ventana.stackgroup.size=[tamanoX,tamanoY];

    ventana.stacksubgroup1 = ventana.stackgroup.add(“group”);
    ventana.stacksubgroup1.location=[puntoX1,puntoY1,puntoX2,puntoY2];
    ventana.stacksubgroup1.size=[tamanoX,tamanoY];
    ventana.stacksubgroup1.add(“statictext”,[10, 40, 90, 60], “A TOOL”);
    ventana.stacksubgroup1.add(“edittext”,[100,40,195,60],”Sin Nombre”);
    ventana.stacksubgroup1.add(“button”,[100,70,195,90],”apply”)

    ventana.stacksubgroup2 = ventana.stackgroup.add(“group”);
    ventana.stacksubgroup2.location=[puntoX1,puntoY1,puntoX2,puntoY2];
    ventana.stacksubgroup2.size=[tamanoX,tamanoY];
    ventana.stacksubgroup2.add(“statictext”,[10, 40, 90, 60], “B TOOL”);
    ventana.stacksubgroup2.add(“edittext”,[100,40,195,60],”Sin Nombre”);

    ventana.stacksubgroup3 = ventana.stackgroup.add(“group”);
    ventana.stacksubgroup3.location=[10, 10, 200, 30];
    ventana.stacksubgroup3.size=[200,30];
    ventana.stacksubgroup3.add(“statictext”,[10, 10, 60, 30],”Tool”);
    var toolMenu=ventana.stacksubgroup3.add(“dropdownlist”,[70, 10, 195, 30],[“A”,”B”,”C”,”D”,”E”]);

    toolMenu.selection=0;
    ventana.stacksubgroup1.visible=true;
    ventana.stacksubgroup2.visible=false;

    toolMenu.onChange=function fcreateUIS(){
    var toolSelection = toolMenu.selection.index;

    ventana.stacksubgroup1.visible = (toolSelection==0);
    ventana.stacksubgroup2.visible = (toolSelection==1);
    };

    return(ventana);
    }

    var pal = createUI(this);
    pal;

  • Xavier Gomez

    December 31, 2012 at 11:39 am

    Hello,
    i’m not sure i can help you more than that… i tried your code and it doesnt show the palette for me. (result: [object Window] and that’s all). However if i write pal.show() instead of simply pal at the end, it does show the palette.

    Also for alignments and item positions in the palette, i’m not used to coordinates, it seems extremely clumsy and hard to modulate. I have no idea why entering orientation/alignment instructions doesnt work for you (such as ventana.stackgroup = ventana.add(“group {orientation: ‘stack’}”); etc). Maybe a version issue but i doubt it (i’m using CS5.5).

  • Mateo Mazzini

    December 31, 2012 at 12:50 pm

    maybe it’s a difference between common scripts and scripts UI… if I open the script from “file/run script file/” it doesn’t work, but once i put the script in the after effects folder “ScriptUI Panels” and restart after effects, it shows up in the window menu. From there it does work… but, it’s also there where I have problems with the alignment.
    When i wrote the code for a common script, I could let the alignment under “undefined” and it would work, ebut when I made the change to Script UI, I had to give the code specifics coordinates…

    Matz

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