Skip to main content
Known Participant
April 18, 2014
Answered

Use GUI checkbox for scripting

  • April 18, 2014
  • 2 replies
  • 2148 views

Hi There

How can I use the GUI checkbox option in my script to turn Motion Blur ON or leave it OFF?

For example I´ve generated this checkbox in my GUI Panel:

var checkMB = groupTwo.add("checkbox", undefined, "Motion Blur ON");

How can I ask if it is checked or not and use this information.

For this example I want to ask "if I plan to use Motion Blur". And if so, the Motion Blur Button in the Timeline should set to ON.

I found some code for the Shy Button, but nothing for the MB button. (xxx.hideShyLayers = true;)

This topic has been closed for replies.
Correct answer Paul Tuersley

To get the state of the checkbox you would use:

checkMB.value

which would return a boolean, true if checked, false if unchecked.

i.e. if (checkMB.value == true)

or, since the if statement is only testing if the argument is true/false you could just do

if (checkMB.value)

To set the comp's motion blur, which also requires a boolean value, you could do:

myComp.motionBlur = checkMB.value;

The motionBlur attribute of the CompItem object is covered on page 56 of the CS6 Scripting Guide pdf.

Paul

2 replies

Legend
April 18, 2014

A checkbox gui element has a .value property of boolean type that you can read so you can handle your script's flow properly.  You may want to assign the value to a global variable when the user clicks it with its .onClick() method.  If the value is stored globally, all of your script's functions will have access to it.  To avoid placing it in global memory, just pass the value around to the functions that need it, or have the functions scan the .value property of the checkbox.

The code is something like this:

var USE_MOTION_BLUR = checkMB.value;

function doSomethingCool()

{

     if (USE_MOTION_BLUR) {

          //fancy motion blur code here

     }

}

--Arie

Paul TuersleyCorrect answer
Inspiring
April 18, 2014

To get the state of the checkbox you would use:

checkMB.value

which would return a boolean, true if checked, false if unchecked.

i.e. if (checkMB.value == true)

or, since the if statement is only testing if the argument is true/false you could just do

if (checkMB.value)

To set the comp's motion blur, which also requires a boolean value, you could do:

myComp.motionBlur = checkMB.value;

The motionBlur attribute of the CompItem object is covered on page 56 of the CS6 Scripting Guide pdf.

Paul

ab_VFXAuthor
Known Participant
April 19, 2014

To both of you ::: Thank You. Both codes do the right thing.

I think Paul´s third line do the job for me!

Paul ... I´ve searched the reference for that piece of code, but did not find it. Have to make more breakes after reading and trying and reading and trying ..... ;-)