Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

What script to create a comp with an Ui Panel

New Here ,
Aug 31, 2015 Aug 31, 2015

Hello Guys,

So I'm new in the scripts and  javascript and I try to do it simple. I'm a VJ and want to create a script where I enter a "BPM" and a "beat" lengh and it generate me a comp with the right lengh and ass a layer with a marker ofr each beat.

I was able to create that script but As I try to make it look a bit better with a UI integration for AE I was not able to make it work right. If someone can help me or give me some tips. I think I'm not right with the "addComp" expression in the buildUI function.

I don't copy everythin because it's long but you will understaind the main Idea. My question is how to have the entry in my advanced UI instead of the "prompt"

Here is my first code who does the job :

//Set Var Elements

var name = prompt("Composition name");

var BPM =prompt("Your BPM");

if (isNaN(BPM)) {

    alert("You must give the comp a value");

  }

var Beats = prompt("How Many Beat");

if (isNaN(Beats)) {

    alert("You must give the comp a value");

    }

var frameRate = prompt("Your fps");

if (isNaN(frameRate)) {

    alert("You must give the comp a value");

    }

var duration = ( 60  / BPM * Beats ); //Auto Generated

var beat = (60  / BPM);

//Creation Part

app.project.items.addComp(name, 1920, 1080, 1, duration, frameRate); // Create Comp with Custom Lengh

app.project.item(01).layers.addSolid([0,0,0], "BG", 1920, 1080, 1, duration); // Create BG Solid

var firstLayer = app.project.item(1).layer(1);

firstLayer.label = 16;

app.project.item(01).layers.addSolid([0,0,0], "FX", 1920, 1080, 1, duration); // Create FX Solid

app.project.item(01).layers.addNull(duration); // Create Null Object

var firstLayer = app.project.item(1).layer(1); // Rename Null Object

firstLayer.enabled = false;

firstLayer.name = "Beats";

firstLayer.label = 0;

// Place a marker on the 64 first beat

var myMarker = new MarkerValue("0");

firstLayer.property("Marker").setValueAtTime(beat*0, myMarker);

// Key every Beat on opacity

myProperty = firstLayer.opacity;

myProperty.setValueAtTime(beat*0, 0);


TOPICS
Scripting
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Sep 02, 2015 Sep 02, 2015

For reference, I'm gonna place Dan's code here and use the line numbers as I explain.

Fig. A

var name = prompt("Composition name");

var BPM =prompt("Your BPM");

if (isNaN(BPM)) {

    alert("You must give the comp a value");

  }

var Beats = prompt("How Many Beat");

if (isNaN(Beats)) {

    alert("You must give the comp a value");

    }

var frameRate = prompt("Your fps");

if (isNaN(frameRate)) {

    alert("You must give the comp a value");

    }

var duration = ( 60  / BPM * Beats ); //Auto Genera

...
Translate
Community Expert ,
Aug 31, 2015 Aug 31, 2015

I made a few edits:

var name = prompt("Composition name");

var BPM =prompt("Your BPM");

if (isNaN(BPM)) {

    alert("You must give the comp a value");

  }

var Beats = prompt("How Many Beat");

if (isNaN(Beats)) {

    alert("You must give the comp a value");

    }

var frameRate = prompt("Your fps");

if (isNaN(frameRate)) {

    alert("You must give the comp a value");

    }

var duration = ( 60  / BPM * Beats ); //Auto Generated

var beat = (60  / BPM);

//Creation Part

var myComp = app.project.items.addComp(name, 1920, 1080, 1, duration, frameRate); // Create Comp with Custom Lengh

var firstLayer = myComp.layers.addSolid([0,0,0], "BG", 1920, 1080, 1, duration); // Create BG Solid

firstLayer.label = 16;

myComp.layers.addSolid([0,0,0], "FX", 1920, 1080, 1, duration); // Create FX Solid

firstLayer = myComp.layers.addNull(duration); // Create Null Object

firstLayer.enabled = false;

firstLayer.name = "Beats";

firstLayer.label = 0;

// Place a marker on the 64 first beat

var myMarker = new MarkerValue("0");

firstLayer.property("Marker").setValueAtTime(beat*0, myMarker);

// Key every Beat on opacity

var myProperty = firstLayer.opacity;

myProperty.setValueAtTime(beat*0, 0);

Dan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Sep 01, 2015 Sep 01, 2015

As far as the UI is concerned, this post I did will give you the base code for making a dockable UI.

[Free Source code] Dockable & floating panel with controls

This core code here....

res="group{orientation:'column', alignment:['fill', 'fill'], alignChildren:['fill', 'fill'],\

     myStaticText: StaticText{text:'StaticText Text'},\

     myEditText: EditText{text:'EditText text'},\

     myButton: Button{text:'Button Name'},\

     myCheckbox: Checkbox{text:'Checkbox Name'},\

     myRadioButton: RadioButton{text:'RadioButton Name'},\

     myDropDownList: DropDownList{properties:{items:['Item 1 Name', 'Item 2 Name', 'Item 3 Name', 'Item 4 Name']}},\

     myListBox: ListBox{properties:{items:['Item 1 Name', 'Item 2 Name', 'Item 3 Name', 'Item 4 Name']}},\

     myGroup: Group{orientation:'row', alignment:['fill', 'fill'], alignChildren:['fill', 'fill'],\

          myGroupItem1: Button{text:'Hi'},\

          myGroupItem2: Button{text:'Hello'},\

          myGroupItem3: Button{text:'Goodbye'},\

     },\

     myPanel: Panel{text:'Panel Name', orientation:'column', alignChildren:['right', 'fill'],\

          myPanelItem1: Button{text:'One'},\

          myPanelItem2: Button{text:'Two'},\

          myPanelItem3: Button{text:'Three'},\

     },\

     myTabbedPanel: Panel{type:'tabbedpanel', text:'Tabbed Panel Name', orientation:'column', alignChildren:['right', 'fill'],\

         myTab1: Panel{type:'tab', text:'Tab 1', orientation:'column', alignChildren:['right', 'center'],\

             aButton1: Button{text:'Button1'},\

         },\

         myTab2: Panel{type:'tab', text:'Tab 2', orientation:'column', alignChildren:['left', 'center'],\

             aButton2: Button{text:'Button2'},\

         },\

               },\

     myProgressBar: Progressbar{text:'Progressbar Name', minvalue:0, maxvalue:100, value:50},\

}"

can be paired down to just two controls for you to enter BPM and a button to launch the comp creation...

res="group{orientation:'column', alignment:['fill', 'fill'], alignChildren:['fill', 'fill'],\

     myEditText: EditText{text:'Enter BPM'},\

     myButton: Button{text:'Create comp'},\

}"

That will create the UI, but you still need to assign both controls to variables and then setup the onClick for the button variable to run Dan's code. Hopefully that sheds some light on the UI part. If you need more help, let me know.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 02, 2015 Sep 02, 2015

Ohh thank you so much !

I had already create a custom UI but this helped me to make it more clean and understand a lot of things.

But my real problem is that I don't find the way to connect the controls & the variables and make the comp created on the "click" action. I try to copy a lot of other basic script but don't know why it doesn't work on mine.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Sep 02, 2015 Sep 02, 2015

For reference, I'm gonna place Dan's code here and use the line numbers as I explain.

Fig. A

var name = prompt("Composition name");

var BPM =prompt("Your BPM");

if (isNaN(BPM)) {

    alert("You must give the comp a value");

  }

var Beats = prompt("How Many Beat");

if (isNaN(Beats)) {

    alert("You must give the comp a value");

    }

var frameRate = prompt("Your fps");

if (isNaN(frameRate)) {

    alert("You must give the comp a value");

    }

var duration = ( 60  / BPM * Beats ); //Auto Generated

var beat = (60  / BPM);

//Creation Part

var myComp = app.project.items.addComp(name, 1920, 1080, 1, duration, frameRate); // Create Comp with Custom Lengh

var firstLayer = myComp.layers.addSolid([0,0,0], "BG", 1920, 1080, 1, duration); // Create BG Solid

firstLayer.label = 16;

myComp.layers.addSolid([0,0,0], "FX", 1920, 1080, 1, duration); // Create FX Solid

firstLayer = myComp.layers.addNull(duration); // Create Null Object

firstLayer.enabled = false;

firstLayer.name = "Beats";

firstLayer.label = 0;

// Place a marker on the 64 first beat

var myMarker = new MarkerValue("0");

firstLayer.property("Marker").setValueAtTime(beat*0, myMarker);

// Key every Beat on opacity

var myProperty = firstLayer.opacity;

myProperty.setValueAtTime(beat*0, 0);

Ok, so for your setup, it looks like you are grabbing four sets of data. You have the comp name (Fig. A line 1), BPM (Fig. A lines 2-5), beats (Fig. A lines 7-10), and the FPS (Fig. A lines 12-15). So as far as UI goes, you can modify what I had posted to...

res = "group{orientation:'column', alignment:['fill', 'fill'], alignChildren:['fill', 'fill'],\

  myCompName: EditText{text:'Enter comp name'},\

  myBPM: EditText{text:'Enter BPM'},\

  myBeats: EditText{text:'Enter beats'},\

  myFPS: DropDownList{properties:{items:['23.976', '24', '29.97', '30', '59.97', '60']}},\

  createComp: Button{text:'Create comp'},\

}"

This will give you all four data entries for the UI. It's best to assign each control to a new variable for ease of use within your script.

// Control Variables

  var compName = myPanel.grp.myCompName;

  var myBPM = myPanel.grp.myBPM;

  var myBeats = myPanel.grp.myBeats;

  var fps = myPanel.grp.myFPS;

  var createComp = myPanel.grp.createComp;

Once you have those variables you can then start setting up defaults if any. in this case, the dropdown would need a starting point for it's selection, so you can tell it to use the first entry by default like so.

//Defaults

  fps.selection = 0;

Now you can setup your onClick functionality for the createComp button. This will contain to working part of Dan's code that processes everything (Fig. A lines 17-33). I added a few extras lines above this (Fig. B lines 1-7) in the below code just to match the variable names so you wouldn't need to change any of his code.

Fig. B

//onClick setups

  createComp.onClick = function(){

  //Gather user entered values

  var name = compName.text;

  var BPM = Number(myBPM.text);

  var Beats = Number(myBeats.text);

  var frameRate = fps.selection.text;

  var duration = ( 60  / BPM * Beats );

  var beat = (60  / BPM);

  //Creation Part

  var myComp = app.project.items.addComp(name, 1920, 1080, 1, duration, frameRate);

  var firstLayer = myComp.layers.addSolid([0,0,0], "BG", 1920, 1080, 1, duration);

  firstLayer.label = 16;

  myComp.layers.addSolid([0,0,0], "FX", 1920, 1080, 1, duration);

  firstLayer = myComp.layers.addNull(duration);

  firstLayer.enabled = false;

  firstLayer.name = "Beats";

  firstLayer.label = 0;

  // Place a marker on the 64 first beat

  var myMarker = new MarkerValue("0");

  firstLayer.property("Marker").setValueAtTime(beat*0, myMarker);

  // Key every Beat on opacity

  var myProperty = firstLayer.opacity;

  myProperty.setValueAtTime(beat*0, 0);

  }

So Fig. B line 2 begins the onClick call for the button and assigns a function to it. Within the function we run the process. Fig. B Line 4 grabs the compName edit text control's text attribute, Fig. B line 5 gets the BPM edit text control's text attribute and by using the function Number() we convert that text to a number for use in Fig. B line 9 and 10. The same applies to Fig. B line 6 and the Beats variable. For Fig. B line 7, a dropdown requires calling it's selection attribute, then it's text attribute to get the actual string. The dropdown made more sense for the FPS due to standard rates that exist. This list can be modified of course to your liking. Now there are no safety nets as I like to call them for the edit text controls to make sure text isn't entered when you need a number and vice versa. This would be something to can verify after Fig. B line 7, before trying to run the process code (Fig. B lines 9-25). Hopefully that will be easy enough for you to figure out.

So the whole script would look like this.

{

function myScript(thisObj) {

  function myScript_buildUI(thisObj) {

  var myPanel = (thisObj instanceof Panel) ? thisObj : new Window("palette", "My Panel Name", [0, 0, 300, 300]);

  res="group{orientation:'column', alignment:['fill', 'fill'], alignChildren:['fill', 'fill'],\

  myCompName: EditText{text:'Enter comp name'},\

  myBPM: EditText{text:'Enter BPM'},\

  myBeats: EditText{text:'Enter beats'},\

  myFPS: DropDownList{properties:{items:['23.976', '24', '29.97', '30', '59.97', '60']}},\

  createComp: Button{text:'Create comp'},\

  }"

  //Add resource string to panel

  myPanel.grp = myPanel.add(res);

  // Control Variables

  var compName = myPanel.grp.myCompName;

  var myBPM = myPanel.grp.myBPM;

  var myBeats = myPanel.grp.myBeats;

  var fps = myPanel.grp.myFPS;

  var createComp = myPanel.grp.createComp;

  //Defaults

  fps.selection = 0;

  //onClick setups

  createComp.onClick = function(){

  //Gather user entered values

  var name = compName.text;

  var BPM = Number(myBPM.text);

  var Beats = Number(myBeats.text);

  var frameRate = fps.selection.text;

  var duration = ( 60  / BPM * Beats );

  var beat = (60  / BPM);

  //Creation Part

  var myComp = app.project.items.addComp(name, 1920, 1080, 1, duration, frameRate);

  var firstLayer = myComp.layers.addSolid([0,0,0], "BG", 1920, 1080, 1, duration);

  firstLayer.label = 16;

  myComp.layers.addSolid([0,0,0], "FX", 1920, 1080, 1, duration);

  firstLayer = myComp.layers.addNull(duration);

  firstLayer.enabled = false;

  firstLayer.name = "Beats";

  firstLayer.label = 0;

  // Place a marker on the 64 first beat

  var myMarker = new MarkerValue("0");

  firstLayer.property("Marker").setValueAtTime(beat*0, myMarker);

  // Key every Beat on opacity

  var myProperty = firstLayer.opacity;

  myProperty.setValueAtTime(beat*0, 0);

  }

  //Setup panel sizing and make panel resizable

  myPanel.layout.layout(true);

  myPanel.grp.minimumSize = myPanel.grp.size;

  myPanel.layout.resize();

  myPanel.onResizing = myPanel.onResize = function () {this.layout.resize();}

  return myPanel;

  }

  var myScriptPal = myScript_buildUI(thisObj);

  if ((myScriptPal != null) && (myScriptPal instanceof Window)) {

  myScriptPal.center();

  myScriptPal.show();

  }

  }

  myScript(this);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 10, 2015 Sep 10, 2015
LATEST

David Torro your are amazing !

Thank you so much man, this does a great job and I've understand the way it work. I will do some other scripts for the Vj community and share you the links here

Once more, thank you guys !

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines