Skip to main content
Known Participant
June 10, 2015
Question

assign a action/function to a button

  • June 10, 2015
  • 7 replies
  • 1908 views

Hi.

I have followed David Torno's extendscript series.

I can't seem to figure out something as simple as assigning a action  to my button.

the button is in the res variable.

//  res = "group {orientation; 'row',\

                groupOne: Group{orientation: 'column',\

                MinButton: Button{text: 'knap'},\

},\

}";

myPanel.grp= myPanel (res);

//

How do I add this code to the button,which basically add a new comp to the project window.

//

app.project.items.addComp("newComp", 1920,1080, 1

0, 10, 25);

//

Regards HRB

This topic has been closed for replies.

7 replies

hrohibilAuthor
Known Participant
June 21, 2015

Yes it does. Thank you David.

And thank you again for the tutorials. So what I manged to get out of this is this:   I created a window with a user/password fields, (from the other thread thank you :-), if login is verified, then it activates the progressbar and the bar Counts up with text and all. When the bar reaches 100%, then another button below the bar becomes visible and when you click that, it opens up another window.

So this is all for learning and study purpose only, but I am learning so much thanks to you.....

Cheers

Hamid

Legend
June 23, 2015

You are welcome, glad you are learning and enjoying the process.

hrohibilAuthor
Known Participant
June 20, 2015

Hmm. Okay, still learning... I changed the max values on the " minvalue:0, maxvalue:100", then it worked, Do I have to have a minValue/maxValue all the time I am using a progressbar??  I mean can it be self dynamiclly updating?? 

I.e  when i tried on comp2 with only 3 layers, and I have set the maxValue to 100, then it only displays 3 out 100 on the bar....

Also I had to change the "i <" to add a equal to it like so "i <=" in order to get the 100% and not the 99%...

Legend
June 20, 2015

Also I had to change the "i <" to add a equal to it like so "i <=" in order to get the 100% and not the 99%...

Correct, line #31 in the above code has the "=" to get the percentage value to the full 100%.


I.e  when i tried on comp2 with only 3 layers, and I have set the maxValue to 100, then it only displays 3 out 100 on the bar....


Also correct, if your full total of processing pieces are different values, then you need to reset the progressBarElement.maxValue to the new total. Usually you can run a quick tally of the total number of item going to be processed before hand and just set the maxValue to that, but in some cases, you may not know the grand total up front so you may need to have a starting maxValue and then add additional totals to that along the way. You would do this by reading the current maxValue and then adding your extra total to it, then reassigning this new value to the maxValue. Hopefully that makes sense.

hrohibilAuthor
Known Participant
June 20, 2015

Hi David

I created a comp item(1) and created 182 layers within that comp.

I want to link the progressbar to the loop like you said, so as i am going through them all, the progressbar should display.

Here is the code:

// PROGRESS BAR SET TO VISIBLE FALSE

    myStaticText.visible = true;  // False original

    progressBar.visible = true;  // False original

   

    myProBTN.onClick = function() {

                 

   

     var proj = app.project;

     var myTotalItems = proj.item(1).numLayers;

    

     myStaticText.visible = true; 

     progressBar.visible = true;

   

    for(var i=0; i < myTotalItems; i++ ){

         percentage = Math.floor((i/myTotalItems)*100);

         myStaticText.text = percentage.toString() + "%";

         progressBar.value++; //Increases the progressbar value each loop

        

       

        }

       }

What am I missing here....   Please see the image below. When I hit the show progress button, the counter goes to 99% straight away, there is no visible color or movement from the the progressbar.

Then I created a another comp, with only 4 layers in it, when i run the script here, it goes straight away to 66 % and again with no movement...

Why does the counter not go up to 100% and why cant i see any movement in the actual bar??

Cheers

Hamid

hrohibilAuthor
Known Participant
June 20, 2015

Ok. somehow by entering that line in manually, it worked... Thank you David..

I will see how this is connected. You just picked a random number 900000 to give it some time so we can see the progress.

hrohibilAuthor
Known Participant
June 20, 2015

Hi David

Please look at my screenshot, it does the same thing just like the other script you provided, it displays the error sound and highlights line 6. I am using extendscript cs6

I am really looking forward to learn this script

Cheers Hamid

Legend
June 11, 2015

HRB, apologies for not showing that in the tutorial. Xavier is correct in how to use the handler call for your button.

The basic formation of code will be similar when checking for values or running your custom code. It would look similar to this.


controlElement.onClick = function(){

     //Run your code here

}

controlElement.onChange = function(){

     //Run your code here

}

controlElement.onChanging = function(){

     //Run your code here

}

...and so on.

In the JavaScript-Tools-Guide-CC.pdf under the "Control types and creation parameters" section on Pg. 124 You will see a breakdown of element types (button, checkbox, etc.), and next to them a description that will talk about what event handler calls are made (onClick, onChange, and onChanging). Also under the "Control event-handling callbacks" on Pg. 147 you will see all of the handlers listed and to which control element they work with.

hrohibilAuthor
Known Participant
June 19, 2015

Sorry for late reply.

Thank you for those links. I will definitely check them out. I managed with help from you and Dan to assign a call event to the slider button. So that when I have a selected layer, then the slider when moved will lower or up the opacity. I am using the on change,  not sure what the onChanging will do, maybe for the slider to update dynamicly and not when I release the button.

Anyways I am trying to figure out how to connect or activate the progressbar.  I know you go through it in one of your last big projects from the series

Cheers

Hamid

hrohibilAuthor
Known Participant
June 19, 2015
not sure what the onChanging will do

It works well with sliders and edittext elements. For a slider you can have a statictext readout of the slider value in realtime. For edittext, you can validate the text being typed as it is typed. It's a handy method to use.

Anyways I am trying to figure out how to connect or activate the progressbar.

Depending on how you are displaying the progressbar (popup window, in script UI, etc....). It's simply best to play the progressbar value updater in the loop processing the data you want to show progress on. I do build a progressbar in this tutorial http://www.provideocoalition.com/after-effects-extendscript-training-ep-18 you'll have to skip through the video for the different moments I talk about it.


Thanks David.

I will try to go through your video and see if I can piece something together. I want to keep it simple just to learn it.

UQg
Legend
June 10, 2015

use the button onClick handler, something like this:

myPanel.grp.groupOne.MinButton.onClick = function(){

    app.project.items.addComp("newComp", 1920,1080, 10, 10, 25);

    return;

    };

Xavier